Skip to content

Wrong type for DraftFunction? #135

Open

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.

Activity

  1. simonlsk commented on Sep 15, 2024

    @simonlsk

    Correct, encountering the same issue.

  2. mweststrate commented on Sep 27, 2024

    @mweststrate
    Collaborator

    PR welcome

  3. gbarrett-makeit commented on Mar 7, 2026

    @gbarrett-makeit

    I've made a PR here #149. Note to anyone stumbling across this, the code for the hook is about 20 lines long and you can easily make your own copy of it in your project if you so desire.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions