-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
Typescript: Cannot assign immutable state from payload to immutable writable draft #1127
Closed
1 of 3 tasks
Comments
It seems |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🐛 Bug Report
Immer exposes a
Immutable
helper type that deeply mark a type as readonly:Immer also conveniently make it so that a
WritableDraft<...>
will let you assign to subobjects since immer will not mutate the original state, which is correct:However, writable draft don't let an immutable value be assigned to another immutable value:
This is technically correct as
arr
will be assigned to another mutable valueThis issue arises a lot when you have an immutable state in redux, use a selector and send back a state in an action payload. When action payloads are immutable, this issue will trigger.
Link to repro
A bug report without a reproduction is not a bug report. Failing to follow this templately is likely to result in an immediate close & lock of the issue.
CodeSandbox demo
To Reproduce
Steps to reproduce the behavior:
Observed behavior
Typescript refuses the code
Expected behavior
Typescript should accept the code
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: