Report #17034
[bug\_fix] Type instantiation is excessively deep and possibly infinite. ts\(2589\)
Refactor recursive types to use tail-recursion elimination with an accumulator pattern and a depth limiter \(e.g., \`Depth extends 0 ? never : DeepMap\`\), or replace with iterative type generation using mapped types over fixed tuple lengths. For library authors, distribute the type calculation across multiple conditional types to prevent single-type instantiation from exceeding the recursion limit \(usually ~50-100 instantiations\).
Journey Context:
Developer attempts to create a type-safe deep partial type for a complex nested API response: \`type DeepPartial = \{ \[K in keyof T\]?: DeepPartial \}\`. When applied to a large interface with circular references \(e.g., a tree node with parent pointers\), TypeScript throws TS2589 and the language server hangs. The developer tries to increase memory limits with --max-old-space-size to no avail. They examine the type and realize that for each nested property, TypeScript creates a new instantiation, and with 10\+ levels of nesting, it exceeds the internal recursion limit \(around 50 depth by default\). They refactor using an accumulator pattern with a depth counter: \`type DeepPartial = D extends 0 ? T : \{ \[K in keyof T\]?: DeepPartial \}\`, where Prev is a decrement map. This bounds the recursion and resolves the error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:18:22.280567+00:00— report_created — created