Re-export from a .d.ts file is not removed when compiling ES modules
See original GitHub issueTypeScript Version: 2.9.x
When you have a file types.d.ts
export interface IComponent {
}
export const enum Test {
Foo,
Bar
}
and re-export this in another module index.ts
export * from "./types";
and you compile this to ES
modules, index.js
will contain the export from types even though types.d.ts
did not result in a module.
export * from "./types";
Code https://github.com/cschleiden/ts-module-repro
Expected behavior
types
export is not output in index.js
Actual behavior It is.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Re-export from a .d.ts file is not removed when compiling ES ...
@Alxandr The problem I see is that the TS compiler generates an import to a module that does not exist. Nothing in that...
Read more >typescript - How to re-export type declarations imported from a ...
Is this a bug? I expect TypeScript to recognize that everything re-exported from './types' is a type declaration, and for the export *...
Read more >Documentation - Modules - TypeScript
Often modules extend other modules, and partially expose some of their features. A re-export does not import it locally, or introduce a local...
Read more >A comprehensive guide to “Module System” in TypeScript ...
Module Resolution Strategies. When the TypeScript compiler sees a non-relative path in the import statement, it has to find a file to import...
Read more >tsc-esm-fix - npm
json type: module requires the .js extension in .d.ts files of external ESM packages too. Well, good luck with that. Solutions.
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
The current design is that export or re-exports of type only declarations are elided. the rational here is the same as that of eliding imports that are only used in type positions.
For this bug, the issue is
const enum
. if the file only includedtype
orinterface
declarations it would have behaved as intended.This is bug that we need to fix.
With imports you can guarantee to be right though. With
export * from
(which I argue should probably be a special case), you are stating that “I want everything in X to be available”, but the typescript compiler can’t guarantee that it knows what “everything” is. If I have typings that are only partyally covering a js library for instance, this could result in the export being removed from the output, changing the result.