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

An object type that contains Json causes a recursive error in conjunction with Draft/WritableDraft types from Immer #168

Open
mcmire opened this issue Jan 23, 2024 · 3 comments

Comments

@mcmire
Copy link
Contributor

mcmire commented Jan 23, 2024

If you have an object type such as:

{
  foo: Json
}

and you use it to change state within an Immer produce callback — such the callback that update in BaseController v2 takes — then you will get an error:

Type instantiation is excessively deep and possibly infinite

This is happening because Json is a recursive type and Draft and WritableDraft trampoline as they recurse through that Json type. There's an open bug report on the Immer issue tracker with a proposed fix that was eventually reverted.

We should work out some way to avoid this.

@MajorLift
Copy link
Contributor

MajorLift commented Jan 24, 2024

Some starting points for tackling the "Type instantiation is excessively deep" error:

This might not be enough to resolve the issue if the mutual recursion depth is infinite even with tail call elimination.

@MajorLift
Copy link
Contributor

Might be resolved by TypeScript 5.5: microsoft/TypeScript#57293

montelaidev added a commit to MetaMask/core that referenced this issue May 29, 2024
## Explanation

This PR is a temp fix for the type error `Type instantiation is
excessively deep and possibly infinite.` when updating the state.

## References

Related to: MetaMask/utils#168

## Changelog

### `@metamask/accounts-controller`

- **FIXED**: Type error during state update

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
MajorLift added a commit to MetaMask/core that referenced this issue Jul 11, 2024
@mcmire
Copy link
Contributor Author

mcmire commented Oct 28, 2024

I checked the Immer repo and it looks like this problem still exists: immerjs/immer#839

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

No branches or pull requests

2 participants