When looking at the code snippet below, we encounter an error on line 2 stating
Property 'newProperty' does not exist on type 'WritableDraft<MyObject>'. TS7053
// data is of type MyObject which until now has only a property myNumber
const payload = produce(data, (draft) => {
draft['newProperty'] = 'test'; // Property 'newProperty' does not exist on type 'WritableDraft<MyObject>'. TS7053
});
Is there a way to dynamically add a new property to the draft or modify the type of the draft to one that already includes the newProperty
? I prefer not to alter the MyObject
type to include newProperty
.