TypeScript - Recursive types: Type instantiation is excessively deep and possibly infinite - ts(2589)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 881
- PR merge metrics
- No merged PRs in 30d
Description
🐛 Bug Report
I'm using immer in a TypeScript project together with the type-fest library. type-fest got updated to 2.0.0 recently and since then the produce method throws the following TypeScript compiler error when used with a JsonObject type from type-fest:
Type instantiation is excessively deep and possibly infinite - ts(2589)

The error appears as soon as the draft variable is added to the produce method. There have been changes to the JsonObject type in type-fest, but it doesn't seem that a lot has changed in the type structure. These are the changes between the 1.4.0 and 2.0.0
Potentially related to #347.
Link to repro
To Reproduce
Open the Codesandbox
Observed behavior
TypeScript throws a compilation error:
Type instantiation is excessively deep and possibly infinite - ts(2589)
Expected behavior
TypeScript should not throw any error
Environment
We only accept bug reports against the latest Immer version.
- Immer version: 9.0.5
- TypeScript version: 4.3.5
- I filed this report against the latest version of Immer
- Occurs with
setUseProxies(true) - Occurs with
setUseProxies(false)(ES5 only)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked CodeSandbox repro using Immer 9.0.5, TypeScript 4.3.5, and type-fest 2.0.0, then compare the linked type-fest 1.4.0 to 2.0.0 changes. Investigate why adding the draft variable to produce triggers ts(2589); done means the repro compiles without that error while preserving the expected produce behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100