Recursion Depth and Limits
Understand TypeScript's recursion depth constraints.
TypeScript Has Recursion Limits
Recursive types are powerful, but the type checker limits how deeply it will instantiate them. Hit the limit and you get a depth error.
// Excessively deep recursive types can produce:
// "Type instantiation is excessively deep and possibly infinite."Where Depth Errors Come From
Conditional types that recurse without a clear, shrinking base case can spiral, especially when combined with large unions or tuple building.
type Repeat<N extends number, Acc extends unknown[] = []> =
Acc["length"] extends N ? Acc : Repeat<N, [...Acc, unknown]>;
// Large N can exceed the instantiation depth.
type Five = Repeat<5>;All lessons in this course
- Recursive Type Definitions
- Typing Tree Structures
- JSON Value Types
- Recursion Depth and Limits