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.

Emmited Type Declarations generate empty export

See original GitHub issue

Bug 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:open
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Oct 28, 2022

Cool, thanks for clarifying – the additional export { } indeed shouldn’t be there.

1reaction
cristobalcommented, Oct 28, 2022

The file needs at least one export or import to be a module. If there already is one, an additional empty one is not needed.

I don’t think the documentation needs to justify every behavior needed for correctness. Correctness is an assumed facet of operation.

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.:

Screenshot 2022-10-28 at 20 12 32

Playground link here

No reference used that is not exported no empty export:

Screenshot 2022-10-28 at 20 16 01

Playground link here

Read more comments on GitHub >

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

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