Description
π Search Terms
declaration, d.ts, import, optimisation
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β Suggestion
Hello!
We are using our dependency injection library in our project (https://github.com/raveclassic/injectable-ts)
And this library allows us to describe big dependency trees
All works fine, but if I open the d.ts
file, which I have as output of my library I see the huge amount of repetition:

In the image, you can see that I have 3702 imports of the library, instead of importing it just once
As I understand, if we import something and not declare or export it outside, it will be just a part of the internal d.ts
file logic.
If I understand correctly, this output is a result of the inferred type of the constant, but it looks possible to significantly optimise this file by importing all types once and then just reusing them
My TypeScript version: 5.3.3
π Motivating Example

π» Use Cases
- Reduce d.ts file size
- Reduce compilation time based on new d.ts shape