Skip to content

Wrong type for DraftFunction? #135

Description

@musjj

export type DraftFunction<S> = (draft: Draft<S>) => void;

It currently specifies void as the return type, but you can actually return a new object, like:

const [state, updateState] = useImmer({ some: "value" });
updateState(() => ({ new: "value" }));

From my observations, it's equivalent to:

updateState({ new: "value" });

I was trying to make a wrapper for the updater function and the wrong function signature tripped me up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions