Emmited Type Declarations generate empty export
See original GitHub issueBug Report
When generating type declaration files if a type that is only used inside the typescript code however it is not exported results in an empty export at the end of the file e.g. export {};
🔎 Search Terms
- declaration empty export
- declaration “export {}”
🕗 Version & Regression Information
When i started inspecting the generated typescript declarations generated.
I see the same error/behaviour when either typescript@4.8
and typescript@next
This is the behavior in every version I tried, and I reviewed the FAQ for entries about emmited code and private fields and methods.
⏯ Playground Link
- When some of the types are not exported this happens playground example here
- When all of the types are exported there is no empty export playground example here
💻 Code
Empty Export Code
type TaskType = 'ONE' | 'TWO' | 'THREE';
// would not expected to have an empty export
// in the emitted type declaration code here is this correct?
export interface Task {
executeTask(type:TaskType):void;
}
No Empty Export
// no empty export since all types and interfaces exported
export type TaskType = 'ONE' | 'TWO' | 'THREE';
export interface Task {
executeTask(type:TaskType):void;
}
🙁 Actual behavior
Empty export for some reason…
🙂 Expected behavior
No default empty export.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
External modules that don't export anything emit empty ...
With the declaration option set to true , the declaration file for b.ts is still generated empty, which makes it impossible to import...
Read more >Generating TypeScript declarations for re-exported JS ...
A good answer will (imo) either: 1. Describe how to generate a proper declaration file when using this "re-export everything from index" style ......
Read more >isolatedModules - TSConfig Option - TypeScript
In TypeScript, you can import a type and then subsequently export it: ... Add an import, export, or an empty 'export {}' statement...
Read more >no-useless-empty-export - TypeScript ESLint
An empty export {} statement is sometimes useful in TypeScript code to turn a file that would otherwise be a script file into...
Read more >TypeScript library tips: Rollup your types! | by Martin Hochel
When authoring a TypeScript library make sure to follow best industry practices like ... By default, TypeScript wont emit declaration files.
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
Cool, thanks for clarifying – the additional
export { }
indeed shouldn’t be there.That was my assumption that there should be not have been any empty
export {}
in the generated declaration file since there is already at least on export defined to make it a module.Seems like a side effect when generating declaration fille, perhaps a bug then? After digging into some here it seems that whenever one references a type, interface or a const value that is not exported the type declaration will include an empty
export {};
at the end of the file.Not exported reference results in empty export example e.g.:
Playground link here
No reference used that is not exported no empty export:
Playground link here