TypeScript "error TS2589: Type instantiation is excessively deep" in CI
The compiler hit its instantiation-depth guard while resolving a recursive or very complex generic type. TS2589 protects against runaway/infinite type computation, but it fails the build.
What this error means
A build fails with TS2589 on a heavily generic expression. It may appear only after a dependency type upgrade or when types grow more complex.
src/query.ts:42:18 - error TS2589: Type instantiation is excessively
deep and possibly infinite.
42 const result = deepMerge(a, b);
~~~~~~~~~~~~~~~Common causes
A recursive generic without a base case
A conditional/mapped type recurses too deeply (or unboundedly), so the compiler stops at its depth limit.
An overly complex inferred type
Chained generic helpers infer a type graph deep enough to trip the guard even though it would eventually terminate.
How to fix it
Add a recursion limit or break the chain
Cap recursion depth in the generic, or split the expression so the compiler infers smaller pieces.
type DeepMerge<A, B, Depth extends number = 5> =
Depth extends 0 ? A : /* ...bounded recursion... */ A;Annotate to stop inference
Provide an explicit type annotation so the compiler does not have to instantiate the deep generic.
const result: MergedShape = deepMerge(a, b);How to prevent it
- Bound recursion in custom generic types with a depth parameter.
- Annotate complex call results to avoid deep inference.
- Pin dependency types and review type-heavy upgrades.