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

[TS] IProduce (external-types.d.ts) curried overloading incorrect -> typecheck pass, runtime fail #877

Open
3 tasks done
akomm opened this issue Dec 3, 2021 · 2 comments

Comments

@akomm
Copy link

akomm commented Dec 3, 2021

🐛 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 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)
@akomm 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
Copy link
Collaborator

Interested in attempting a PR?

@akomm
Copy link
Author

akomm commented Jan 13, 2022

@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

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

No branches or pull requests

2 participants