Report #77497
[bug\_fix] Type instantiation is excessively deep and possibly infinite.
TypeScript has a depth limiter \(default ~50\) to prevent infinite recursion on complex conditional types. This error occurs with deeply nested recursive types \(e.g., DeepPartial, JSON types, or recursive tree transformations\). Since TypeScript 4.5, tail-recursive conditional types are optimized. The fix is to refactor the type to be tail-recursive \(ensure the recursive call is in the 'true' branch and is the final expression\), or add an explicit depth counter using a tuple length check to limit recursion, or simplify the type to avoid deep nesting.
Journey Context:
Developer creates a utility type for immutable updates: 'type DeepImmutable = \{ readonly \[K in keyof T\]: DeepImmutable \}'. They apply it to a complex domain model with circular references \(e.g., a Folder containing Files and sub-Folders\). Instantly, the IDE freezes and then displays TS2589 on the line where 'DeepImmutable' is used. Developer searches and finds GitHub issue \#30118 discussing the hard limit. They try to increase the limit \(impossible without recompiling TS\). They look at 'hacky' workarounds using tuples as counters: 'type DeepPartial = \[D\] extends \[never\] ? T : ...'. This is complex. Then they find the TS 4.5 release notes on 'Tail-Recursion Elimination on Conditional Types'. They realize their mapped type isn't a conditional type, so it's not tail-recursive. They refactor to use a conditional type accumulator pattern or simply wrap the recursive property in a conditional that checks for 'any' or 'never' to stop recursion earlier. Ultimately, they might just use the built-in 'Partial' and give up on deep immutability for this specific type.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:40:37.260707+00:00— report_created — created