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
Typescript has some utility types, ReadonlyArray, ReadonlySet and ReadonlyMap<K, V> but immer doesn't seem to correctly handle these in the Immutable and Draft types.
Motivation
More consistent type checking is in everyone's best interests!
Can this be solved in user-land code?
I could probably write my own typings to override immer's but I would expect this to be something included in immer itself.
Example
import { Draft, produce } from "immer";
let foo: ReadonlySet<string> = new Set();
produce(foo, (draft: Draft<ReadonlySet<string>>) => {
draft.set("bar");
});
…ixesimmerjs#494.
TypeScript provides the ReadonlySet and ReadonlyMap types which match
their normal counterparts but without any methods that mutate their data.
This change makes Immutable<Map> and Immutable<Set> map to those types
directly.
Worth noting that Map extends ReadonlyMap so we only need to check for
one to know what the resulting type is, the same goes for Set and
ReadonlySet.
This also removes the intermediate Set/Map types since TypeScript no
longer seems to need those (likely since TypeScript 3.7, see immerjs#448).
🚀 Feature Proposal
Typescript has some utility types, ReadonlyArray, ReadonlySet and ReadonlyMap<K, V> but immer doesn't seem to correctly handle these in the Immutable and Draft types.
Motivation
More consistent type checking is in everyone's best interests!
Can this be solved in user-land code?
I could probably write my own typings to override immer's but I would expect this to be something included in immer itself.
Example
Result:
`Property 'set' does not exist on type '{ forEach: (callbackfn: (value: string, value2: string, set: ReadonlySet) => void, thisArg?: any) => void; has: (value: string) => boolean; size: number; entries: { ...; }; keys: { ...; }; values: { ...; }; }'
The text was updated successfully, but these errors were encountered: