Report #9305
[bug\_fix] TS2589: Type instantiation is excessively deep and possibly infinite
Refactor the recursive type to use tail-recursion elimination with a depth counter \(e.g., \`type DeepPartial = ...\`\), or use \`interface\` with an index signature instead of recursive mapped types, or break the circularity by using \`unknown\` or \`any\` at a certain depth, or use the type-fest library's implementation which handles this.
Journey Context:
You have a large domain model with recursive types \(e.g., \`interface Category \{ children: Category\[\]; \}\`\). You create a utility type \`type DeepPartial = \{ \[P in keyof T\]?: T\[P\] extends object ? DeepPartial : T\[P\]; \}\` to make everything optional for testing. When you try to use \`DeepPartial\`, TypeScript hangs for a second then reports "Type instantiation is excessively deep and possibly infinite." You check the TypeScript GitHub issues and find that the type checker has a hard limit on recursion depth \(usually 50\). You realize your type is not tail-recursive and keeps expanding \`Category\` -> \`children\` -> \`Category\` infinitely. You find a pattern using a depth counter: \`type DeepPartial = \[D\] extends \[never\] ? T : T extends object ? \{ \[K in keyof T\]?: DeepPartial \} : T;\` \(where \`Prev\` is a utility to decrement\). You implement this depth-limited version, and the error disappears while still providing sufficient depth for your use case.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:47:54.931991+00:00— report_created — created