question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Re-export from a .d.ts file is not removed when compiling ES modules

See original GitHub issue

TypeScript 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:open
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mhegazycommented, Jun 26, 2018

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 included type or interface declarations it would have behaved as intended.

This is bug that we need to fix.

0reactions
Alxandrcommented, Jun 27, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found