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
There is at least one cases of curried produce invocation with provided types, that pass type-check, but fail at runtime. The returned curried function incorrectly accepts undefined as State type-wise, but at runtime the recipe code will fail, when undefined is passed as state. This is because there are two overloading, of which one will always win due to the variance in the context. However, even the second overload which is wrongly picked does not make sense, because it suggests you get initialState as a second argument, which is either impossible or not documented. Both issues are demonstrated in the codesandbox and further explained.
I'v wrote explanation side-by-side with code in Sandbox.
Link to repro
Codesandbox
I'v wrote explanation side-by-side with code.
To Reproduce
Open the Codesandbox and check open the codesandbox's console (tab underneath the preview)
Observed behavior
Curried function returned from producedoes accepts undefined as state.
Expected behavior
Curried function returned from producedoes not accept undefined as state.
Environment
We only accept bug reports against the latest Immer version.
Immer version: 9.0.7
I filed this report against the latest version of Immer
Occurs with setUseProxies(true)
Occurs with setUseProxies(false) (ES5 only)
The text was updated successfully, but these errors were encountered:
akomm
changed the title
[TS] IProduct (external-types.d.ts) curried overloading incorrect -> typecheck pass, runtime fail
[TS] IProduce (external-types.d.ts) curried overloading incorrect -> typecheck pass, runtime fail
Dec 6, 2021
@mweststrate I would. I had not time to figure out what scenario the overloading A (as commented in the codesandbox) is referring to. Did not find any match in the docs. If empty state is not allowed in any case, then the fix would be just remove the overloading. But if it has some use-case, obviously removing is no-opt
🐛 Bug Report
There is at least one cases of curried
produce
invocation with provided types, that pass type-check, but fail at runtime. The returned curried function incorrectly acceptsundefined
asState
type-wise, but at runtime the recipe code will fail, whenundefined
is passed as state. This is because there are two overloading, of which one will always win due to the variance in the context. However, even the second overload which is wrongly picked does not make sense, because it suggests you get initialState as a second argument, which is either impossible or not documented. Both issues are demonstrated in the codesandbox and further explained.I'v wrote explanation side-by-side with code in Sandbox.
Link to repro
Codesandbox
I'v wrote explanation side-by-side with code.
To Reproduce
Open the Codesandbox and check open the codesandbox's console (tab underneath the preview)
Observed behavior
Curried function returned from
produce
does acceptsundefined
as state.Expected behavior
Curried function returned from
produce
does not acceptundefined
as state.Environment
We only accept bug reports against the latest Immer version.
setUseProxies(true)
setUseProxies(false)
(ES5 only)The text was updated successfully, but these errors were encountered: