Microsoft/TypeScript

Emmited Type Declarations generate empty export

Open

#51,338 opened on Oct 28, 2022

View on GitHub
 (10 comments) (1 reaction) (0 assignees)TypeScript (48,455 stars) (6,726 forks)batch import
BugDomain: Declaration EmitHelp Wanted

Description

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.

Contributor guide