You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type error at the marked line is then: Type 'F' cannot be used to index type 'Draft<Readonly<Record<F, number>>>'.
A current workaround is to make the type Bar actually mutable (i.e. remove the Readonly wrapper) and then manually cast the recipe like (draft: Bar<F>) => { /* ... */ }. Both do not feel good or are not possible for the production circumstances.
Are there any alternatives to solve this properly?
🐛 Bug Report
Using generic function arguments around
produce
causes type issues. Its probably best explained with an example (link to CodeSandbox below):The type error at the marked line is then:
Type 'F' cannot be used to index type 'Draft<Readonly<Record<F, number>>>'
.A current workaround is to make the type
Bar
actually mutable (i.e. remove theReadonly
wrapper) and then manually cast the recipe like(draft: Bar<F>) => { /* ... */ }
. Both do not feel good or are not possible for the production circumstances.Are there any alternatives to solve this properly?
Link to repro
Link to CodeSandbox
To Reproduce
Just inspect the error shown in the code editor.
Observed behavior
Type error that correct key type can't be used to index a
Record
wrapped asDraft
.Expected behavior
No type error and the
produce
just works as without a recipe.Environment
We only accept bug reports against the latest Immer version.
v10.1.1
setUseProxies(true)
(I don't know how to apply this, sorry)setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: