Skip to content

How to add new keys? #145

Description

@qcho

Did not find any information about this usecase in the docs

Is there any way to do something like this:

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?

const base = { a: 1 };
const add_b_key = create({...base, b: 1}, (draft) => {
	draft.a = 2;
});

Or I'm missing an utility/setting

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions