Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript - Recursive types: Type instantiation is excessively deep and possibly infinite - ts(2589) #839

Open
1 of 3 tasks
peterjuras opened this issue Aug 7, 2021 · 5 comments · Fixed by #990
Open
1 of 3 tasks

Comments

@peterjuras
Copy link

🐛 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)

immer-example

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

Codesandbox 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)
@denexapp
Copy link

I also have this problem. We use recursive types for app state, and we use the @reduxjs/toolkit package to manage state, which uses immer under the hood.

@unional
Copy link
Contributor

unional commented Oct 30, 2022

I've the same problem with type-plus.
The issue is that the JSONTypes are recursive in nature, so as the Draft<T> tries to resolve a recursive type recursively, it becomes an infinite loop.

@unional
Copy link
Contributor

unional commented Dec 29, 2022

btw, I have fork and released the fix of this in https://github.com/unional/immer, as the PR are not moving.

@elijahbenizzy
Copy link

OK, I have this as well. Really glad to see that others are hitting this too and I'm not crazy 😆

Posting this here for googleability -- do let me know if there's something I can do to help.

Within a nested type I had:

type JSONValue =
    | string
    | number
    | boolean
    | { [x: string]: {} }
    | Array<JSONValue>;```

Which ended up giving me that message. For now I cut out the JSONValue, but happy to look at PRs or do anything else I can do to help!
    

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 9.0.18 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants