immerjs / immer

Create the next immutable state by mutating the current one

Home Page:https://immerjs.github.io/immer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version 9 regression with readonly arrays

Zamiell opened this issue Β· comments

commented

πŸ› Bug Report

When upgrading from immer 8 to immer 9, I get new errors in my codebase from the TypeScript compiler. These errors occur when I assign a new object on a draft state, and that new object contains a substate that has one or more properties that are a readonly array.

Link to repro

Here is a basic minimal reproduction of the error. I'm trying to update the substate of a state, and I get this error.

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgESgQwGbwL5w1CEOAIlBAFMpiBuAKFuADsZKM0BjcuAWQE8BlGGhaJacOFHJoAJhEYAbXnBACArgCNBw8gC4eazUJZ1s9JiyhtO+-hq0iEYiVNkKlAZ0LlBUJgHM9dxhfRj86cUkZOUU4Twoff3c9SNcYoJC-AG0AXRN6DFVGdhhgOTg-chhkcjZVeRg+W0NtAAoASj1GuyMuRwjK1ShGUXFxOO9g-z1iDAgIYgAaJzGvBNCkuEyZucWSdTQqbKXxU1NaAqKSspUAJXJpVU4oADFC4tLGFqDtPVRMGAAPI0egA+NojODsORBZQGexcAC85Uq1Vq9S6zRY7XCsR6ADoVE14XAkYTuto8kA

The error can be removed by changing: readonly someStrings: readonly string[]; --> readonly someStrings: string[];
However, this seems bad - the whole point of using immer in the first place is that you get to have immutable state + immutable data structures. So I'm not sure this "fix" makes sense.

Is this a regression? Or is there some new way that I am supposed to structure my code in immer version 9?

Environment

  • Immer version:
  • I filed this report against the latest version of Immer
  • Occurs with setUseProxies(true)
  • Occurs with setUseProxies(false) (ES5 only)
commented

Thank you!