[utils] An object type that contains `Json` causes a recursive error in conjunction with `Draft`/`WritableDraft` types from Immer
- Dominant language
- TypeScript
- Stars
- 413
- Forks
- 308
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 253
Description
If you have an object type such as:
``` typescript
{
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](https://github.com/immerjs/immer/issues/839) on the Immer issue tracker with a [proposed fix](https://github.com/immerjs/immer/pull/990/files) that was eventually reverted.
We should work out some way to avoid this.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by inspecting the BaseController v2 update callback and the Json, Draft, and WritableDraft types involved in the reported error. Reproduce the type-instantiation failure, then review Immer issue 839 and proposed pull request 990 for possible approaches. Done means object types containing Json can be used in the callback without the recursive TypeScript error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100