ITADN

How to add new keys?

#145Openqcho 创建于 2025-09-25
Q
qchocommented
Did not find any information about this usecase in the docs Is there any way to do something like this: ```ts const base = { a: 1 }; const add_b_key = create(base, (draft) => { draft.a = 2; draft.b = 1; }); ``` getting error on `b`: `Property 'b' does not exist on type 'DraftedObject<{ a: number; }>'.` **Would love to use mutative notation for both new and existing keys.** Are we expected to spread operate the base for new keys? ```ts const base = { a: 1 }; const add_b_key = create({...base, b: 1}, (draft) => { draft.a = 2; }); ```
0 条评论