Consider the following code, where line 2 fails with 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
});
How can I dynamically add a new property to the draft or change the type of the draft to a type which already includes the newProperty
? I do not want to have newProperty
in the MyObject
type itself.
any
? – Torbert