Report #63107
[bug\_fix] Type instantiation is excessively deep and possibly infinite.
Refactor the recursive type to use tail-recursion elimination \(TS 4.5\+\) by ensuring the recursive call is in the true branch of a conditional and uses a type accumulator, or add a depth limiter type parameter \(e.g., \`Depth extends number = 5\`\). Root cause: TypeScript has a hardcoded recursion depth limit \(~50\) to prevent infinite loops during type evaluation; deeply nested mapped types or recursive utility types \(DeepPartial\) on highly nested objects exceed this limit.
Journey Context:
You're building a generic form library and define a \`DeepPartial\` type to make all nested properties optional for draft states. It works fine on shallow objects, but when you try to apply it to a complex database entity with 10\+ levels of nested relations, the IDE hangs and then TypeScript throws 'Type instantiation is excessively deep and possibly infinite'. You first try to increase the memory limit for the TS server, but the error persists. You look at your type definition: \`type DeepPartial = \{ \[P in keyof T\]?: DeepPartial \};\`. You realize that for primitive types, it keeps recursing. You try adding a conditional to stop at primitives: \`T extends object ? ... : T\`, but still hit the limit on deep objects. You research the TypeScript 4.5 release notes and find that tail-recursion elimination was added for conditional types. You refactor using an accumulator pattern and a depth limiter: \`type DeepPartial = \[D\] extends \[never\] ? T : T extends object ? \{ \[K in keyof T\]?: DeepPartial> \} : T;\` where \`Prev\` decrements the number. The error disappears because the recursion depth is now bounded and optimizable by the compiler.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T12:24:21.186870+00:00— report_created — created