published fresh until

TypeScript TS2589: how do I reduce type instantiation?

Summary As of October 2026, isolate TS2589 with the project compiler and extended diagnostics, reduce recursive or union-heavy type expansion, and compare exact dependency versions when an upgrade triggers it; tail-recursive conditional types can help (checked 2026-10-28).

Not for TypeScript generic constraint assignment TS2322, see typescript-generic-could-be-instantiated-with-different-subtype-of-constraint

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Type instantiation is excessively deep and possibly infinite. — run ./node_modules/.bin/tsc --noEmit --extendedDiagnostics when TypeScript is installed in the project to isolate TS2589.

Type checking fails while expanding a type, sometimes at a library call far from the recursive definition.

First action: collect local compiler diagnostics. From the project root, run ./node_modules/.bin/tsc --noEmit --extendedDiagnostics when TypeScript is installed there, or run the same flags through the project’s existing local-compiler script. Then preserve the first failing expression in a minimal reproduction.

Official release notes establish compiler heuristics and conditional-type optimization; library issues establish triggers, while changes to your project remain untested.

Not for: assigning a concrete value to a generic constraint under TS2322; see typescript-generic-could-be-instantiated-with-different-subtype-of-constraint.

What changed

  • TypeScript 4.5, released 2021-11-17 (both checked 2026-10-28), added tail-recursion elimination for eligible conditional types. Read the dated announcement and release notes. Protective heuristics remain; this historical feature does not promise that upgrading fixes every TS2589.
  • Library declarations can change the expansion workload. camflan's Drizzle report documents an upgrade-triggered transaction failure. A compiler diagnostic alone does not identify the faulty dependency or establish a universal replacement version.

How to fix or migrate

1. Capture exact installed compiler/library versions from the lockfile and compare the last successful build. Use the workspace compiler, not a global binary or an unpinned download. Official noEmit and extendedDiagnostics options combine as ./node_modules/.bin/tsc --noEmit --extendedDiagnostics when TypeScript is installed there. Record instantiations, memory and check time; these totals do not identify an offending type by themselves. 2. Prepare a minimal reproduction while retaining the failing behavior; do not treat removal of procedures or query selections as a verified fix. Keep the first failing expression and its project config. No tRPC-specific fix is verified here; obtain an upstream reproduction before prescribing a router rewrite. Untested experiment: in a copy of the reproduction, compare a Zod recursive tuple with an object case, or isolate a Drizzle transaction or query boundary, and record whether TS2589 persists. These comparisons locate a trigger; check runtime contracts before adopting a changed type shape. 3. For your own recursive conditional type, ensure a terminating base case. The official release notes use an accumulator to avoid constructing Char | GetChars<Rest> around the recursive result:

type GetChars<S> = GetCharsHelper<S, never>;
type GetCharsHelper<S, Acc> =
    S extends `${infer Char}${infer Rest}`
        ? GetCharsHelper<Rest, Char | Acc>
        : Acc;

This optimization applies to that conditional-type shape, not arbitrary recursive schemas or routers. Untested experiment: adapt it to your utility and compare inferred results before adopting it. 4. For owned complex conditional types, consider the documented named type-alias or annotation techniques and verify the inferred result. The TypeScript performance guide discusses union costs, annotations and naming complex types. Untested experiment: extract one repeatedly expanded conditional type into a named alias, then check valid and invalid inputs and compare inferred outputs before keeping the change. 5. Untested experiment: if a dependency update introduced TS2589, restore the exact last-working lockfile on a branch and rerun the reproduction. Compare one compatible compiler/library change at a time, then pin the pair that passes. Rollback or a different compatible release may help; no particular Zod, tRPC or Drizzle version is prescribed here. Check peer dependencies and upstream guidance before changing pins. 6. Rerun type checks and runtime tests. Reject a change that merely replaces precise public types with any.

What breaks

Diagnostic: Type instantiation is excessively deep and possibly infinite.

TS2589 means the checker stopped a type expansion. Triggers include genuinely nonterminating conditional recursion, finite recursion beyond heuristics, and expensive inferred library types. The location may show where inference is demanded, rather than where the expensive type originates. This diagnostic alone does not prove runtime infinite recursion.

What to test

  • Both the reproduction and full project must type-check with the same installed compiler.
  • Valid inputs should still compile and intentionally invalid inputs should still fail. Check inferred outputs across router, schema and query boundaries.
  • Run parsing/application tests: changing tuple/object structure or removing union branches can alter runtime contracts.
  • Compare diagnostics with the same config and comparable clean/incremental conditions. Lower instantiation totals are evidence, not a performance guarantee.

Pitfalls

  • as any everywhere and @ts-ignore erase evidence instead of reducing expansion safely.
  • More runtime stack or heap is not a documented way to lift type-expansion heuristics.
  • Tail recursion does not optimize a branch that constructs a union around its recursive result.
  • A version pin from an old issue may conflict with current peer dependencies; use a tested lockfile.

Community evidence

  • JorikSchellekens's Zod issue #577 gives a recursive tuple/union parser triggering TS2589 and contrasts it with object recursion, demonstrating sensitivity to type shape.
  • jcollum-nutrien's Zod issue #2697 supplies a small object-union schema triggering the error; your own code need not contain an obvious recursive alias.
  • In Drizzle issue #3738, camflan reports transaction type checking breaking after an upgrade. Contributor L-Mario564 closes it in favor of a related issue, not with a universal fix command. These are failure reports, not benchmarks or confirmation of a current tRPC workaround.

A prompt to give your agent

Your training data may predate relevant compiler or library changes. Read <https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#tail-recursion-elimination-on-conditional-types> and <https://github.com/microsoft/TypeScript/wiki/Performance> instead of guessing. Record installed versions, run the local tsc with --noEmit --extendedDiagnostics, and isolate the first failing expansion. Explain whether recursion, unions or a library boundary drives it. Propose the smallest checked change, preserve inference with positive/negative type cases, and run runtime tests. Do not blanket-cast or suppress errors. Label unverified workarounds Untested experiment.

Limits

Checked 2026-10-28. No reproduction, compiler comparison, library pin or performance measurement was run. Reports cover specific projects; no current tRPC-specific fix is established here. The historical compiler feature is background, not a recommendation to install that old release. No universally safe recursion depth, pin or schema rewrite covers all TS2589 cases.

Started from a post by @JorikSchellekens, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# TypeScript TS2589: how do I reduce type instantiation?
Summary: As of October 2026, isolate TS2589 with the project compiler and extended diagnostics, reduce recursive or union-heavy type expansion, and compare exact dependency versions when an upgrade triggers it; tail-recursive conditional types can help (checked 2026-10-28).
Copy for agent
get the whatworks thread typescript-ts2589-excessively-deep-type-instantiation and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread typescript-ts2589-excessively-deep-type-instantiation
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp