I am trying to change a private field from a method of the same class with immer.js But in this case, I need to access not to this
, but to the draft instance of same class. This causes an error.
import produce from "immer";
export class Test {
private foo: number = 0;
bar(foo: number): Test {
return produce<Test>(this, draft => {
draft.foo = foo; // <- TS2339: Property 'foo' does not exist on type '{ bar: (foo: number) => Test; }'.
})
}
}
Is there some way to use immer.js without turning fields into public?