Isolated Declarations
--isolatedDeclarations for standalone DTS emit:
since TypeScript 5.5:
Overview
What is isolated declarations?
Today, TypeScript has a many features to help you write better code.
Among them, "type inference" is a particularly important feature.
However, type inference has some problems.
- incurs significant costs
- locked into tsc
At first, costs.
It goes without saying, type inference comes with a cost.
And it is prominent in large code bases.
Tsc must analyze all the code in your project to infer types.
Second, locked into tsc.
There is no alternative to tsc.
There is a famous story about stc wa closed.
TypeScript was not something that I could follow up on in an alternative language.
There are several alternative projects in development, but once completed, they are expected to significantly improve performance.
However, due to various issues such as the lack of a clear specification for TS and the strong resources of Microsoft (implementation not catching up), there is currently no practical alternative to tsc.
New Approach
The new approach is to use "Isolated Declarations".
Isolated declarations (via --isolatedDeclarations option) enforce to write explicit type annotations.
This alleviates the cost of type inference.
There are similar approaches in deno called 'slow types'.
When we emits type declarations (.d.ts), in the past we use --declaration
option.
But there are several issues mentioned above.
Just to summarize more specific details below:
- performance
- cross-file type inference (export/import)
- parallel type inference
For this problem, Isolated Declarations enforces explicit type annotations.