Add option to detect and strip internal exports #58250
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
🔍 Search Terms
✅ Viability Checklist
⭐ Suggestion
I would like TypeScript to be able to detect unused exports and strip them. Most packages define and import and export types that are for internal use only. If
package.json
has theexports
field, TypeScript knows which parts are part of the public interface.📃 Motivating Example
Let’s say you have the following files:
TypeScript emits the following type definitions:
With the option
detectInternal
, TypeScript omits types that aren’t needed for the public interface. Instead of the above, TypeScript would emit:💻 Use Cases
I want to use this option for libraries. Libraries often have such internal exports that are not relevant to the user. These often include types that are imported from other libraries. If TypeScript strips unused exports while compiling a library, it has to load fewer files and process fewer types when a user consumes this library.
Currently a library author can use the
stripInternal
option and@internal
JSDoc tags. This means the author has to manually find and tag internals. This is error prone. It can lead to both false positive and false negative internal markings, without TypeScript complaining.The text was updated successfully, but these errors were encountered: