Alias for TypeScript declaration emitting
See original GitHub issueSearch Terms
- alias
- declaration
Suggestion
A way to configuration alias for declaration files.
Use Cases
Related: #10866
I understand that TypeScript team want to leaves module resolving for other tools like Webpack. However, most of the tools are focus on emitting JavaScript. If you want to emit TypeScript declaration, you need to use tsc
.
This is important when you want to write library with TypeScript that you need to release declaration files.
For example, in Webpack, babel-loader
does not emit declarations, ts-loader
and awesome-typescript-loader
uses tsc
.
Alias is useful for you to write simpler import / export statement.
Examples
index.ts
export * from "~/foo";
index.d.ts
export * from "../../foo";
tsconfig.json
{
"alias": {
"~/*": ["src/*"]
}
}
Checklist
My suggestion meets these guidelines:
- This wouldnβt be a breaking change in existing TypeScript/JavaScript code
- This wouldnβt change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isnβt a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScriptβs Design Goals.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:70
- Comments:13 (1 by maintainers)
Top Results From Across the Web
Typescript declaration file created with alias instead of ...
When I try to consume the library in another typescript app, the build fails due to invalid type declaration file which is being...
Read more >TSConfig Reference - Docs on every TSConfig option
Offers a way to configure the root directory for where declaration files are emitted. example βββ index.ts βββ package.json βββ tsconfig.json.
Read more >Creating type aliases
What a type alias is in TypeScript and the cases where they are useful. ... Now update the score variable declarations to use...
Read more >How to use module path aliases in Visual Studio Code, ...
Typescript does not emit the resolved aliased path to JavaScript, which means that without some help, your JavaScript application won't beΒ ...
Read more >Typescript β How to solve the problem with unresolved path ...
This error actually points to the transpiled('emitted') JavaScript .js file containing the line with the path alias. The actual cause of theΒ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@RyanCavanaugh Sorry for not enough information. Let me describe for the full details.
Folder structure Assume all
index.ts
export all from same level folderTo import
Foo
from foo.ts in bar.ts, you have to write the following.The problem become more serious when you have more level of nested folder.
In Webpack, we can use resolve to handle this (Support babel):
In Jest, we can use
moduleNameMapper
:We also have tsconfig.json to support it in VSCode.
Then, we can write the following instead
These are enough when we are writing an application. However, when I try to write a package in TypeScript, I have to transpile it to JavaScript with TypeScript declaration.
Most of the TypeScript transpilers either does not transpile type declaration or use tsc, for example, babel suggest using
tsc --emitDeclarationsOnly
for declaration as babel does not do type-checking.I have tested out how
tsc --emitDeclarationsOnly
. It emits~/model
without modification. There does not seem to have any tools to handle this for declarations. So, we have to fallback to ββ¦/β¦/β because we have to support declarations.This feature request is some sort of configuration that we can support alias feature in emitting declarations. If TypeScript can resolve with
paths
, it should able to emit declarations with correct paths.Voting for this to be supported