- Error
- Reported by the type checker
TS2589
Type instantiation is excessively deep and possibly infinite.
A recursive generic type expands too deeply for the checker to resolve. Limit the recursion depth or simplify the type.
What it means
Resolving the type needed more nested instantiations than the checker allows, so it stopped. This usually comes from a recursive type alias or conditional type that keeps expanding without reaching a base case the checker can see. tsc reports it at the recursive reference inside the alias; ts-r-check currently reports it where the alias is used.
Example
type Wrap<T> = T extends T ? Wrap<[T]> : never;
type X = Wrap<1>;
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,10): error TS2589: Type instantiation is excessively deep and possibly infinite.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Give the recursion a clear base case, or cap its depth with a counter tuple that stops early.
- Annotate intermediate values with simpler types so the deep type isn't needed.
- Split one large recursive type into smaller steps.