typescript
type_error
ai_generated
partial
error TS2589: Type instantiation is excessively deep and possibly infinite
ID: typescript/ts2589-excessive-stack-depth
78%Fix Rate
85%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
Recursive type exceeded depth limit. Complex conditional/mapped types or circular type references.
genericWorkarounds
-
88% success Simplify the recursive type — add a depth limit parameter
type DeepPartial<T, D extends number = 5> = ...
Sources: https://www.typescriptlang.org/docs/handbook/2/conditional-types.html
-
82% success Break circular type references by using interface instead of type alias
// Break circular type by using interface: // Bad (circular type alias): type Tree = { children: Tree[] }; // may cause recursion // Good (interface handles recursion natively): interface Tree { children: Tree[]; } -
78% success Check if a simpler type utility exists in a library like type-fest
Check if a simpler type utility exists in a library like type-fest
Dead Ends
Common approaches that don't work:
-
Increase TypeScript recursion limit
90% fail
No such config option — the limit is hardcoded for safety
-
Use @ts-ignore on the line
65% fail
Hides the type entirely — you lose all type checking
Error Chain
Preceded by: