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
describe("When the custom map implements Map",()=>{classCustomMapimplementsMap<number,string>{[immerable]=true;count(): number{returnthis.internalMap.size;}//#region Map<number, string> implementation// .....//#endregion}constbase=newCustomMap();base.set(1,"first");it("the draft should be type compatible with CustomMap",()=>{produce(base,(draft)=>{// draft.count(); // TS2339: Property 'count' does not exist on type 'Map<number, string>'.});});it("draft can be hacked with type intersection",()=>{letcount: number|undefined=undefined;produce<CustomMap,Draft<CustomMap>&CustomMap>(base,(draft)=>{count=draft.count();//OK});expect(count).toBe(1);});});
Observed behavior
Draft<CustomMap> is Map<number, string> without CustomMap.count defined.
Expected behavior
Draft<CustomMap> should contain the count property.
Environment
We only accept bug reports against the latest Immer version.
Immer version:
I filed this report against the latest version of Immer
Occurs with setUseProxies(true)
Occurs with setUseProxies(false) (ES5 only)
The text was updated successfully, but these errors were encountered:
That is correct, Immer does not support customised array, Map or Set functionality beyond their standard functionality as per docs:
Immer does not support exotic / engine native objects such as DOM Nodes or Buffers, nor is subclassing Map, Set or arrays supported and the immerable symbol can't be used on them.
🐛 Bug Report
Custom methods defined in
T
is missing inDraft<T>
whenT
implements (not extends)Map
.Related to #502 , #781
Link to repro
https://codesandbox.io/s/immer-sandbox-forked-3n014
To Reproduce
Observed behavior
Draft<CustomMap>
isMap<number, string>
withoutCustomMap.count
defined.Expected behavior
Draft<CustomMap>
should contain thecount
property.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: