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

Add T | Partial<T> to immer middleware's TS return type #2495

Closed
wants to merge 1 commit into from

Conversation

connormanning
Copy link

Related Issues or Discussions

#2491

Summary

The immer middleware adds the capability to modify the Draft<T> in a setState call in-place and not return a partial state value. But the vanilla functionality of returning a T | Partial<T>, without modifying the input state draft, is still supported and works properly.

However, the immer middleware's type definition does not currently contain the T | Partial<T> option and returns only void, which can lead to invalid code compiling cleanly but wrecking the underlying store since anything is assignable to void (see playground). This PR does not add any runtime JS functionality, but adds T | Partial<T> to the immer middleware's return type, so that if you are using immer middleware and you do return a value in a setState, that it will be type-checked.

Check List

  • yarn run prettier for formatting code and docs

Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zustand-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 19, 2024 7:34pm

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@dbritto-dev
Copy link
Collaborator

@connormanning let's review that in this PR #2481, thanks

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

Successfully merging this pull request may close these issues.

None yet

2 participants