Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type for DraftFunction? #135

Open
musjj opened this issue Jul 20, 2024 · 2 comments
Open

Wrong type for DraftFunction? #135

musjj opened this issue Jul 20, 2024 · 2 comments

Comments

@musjj
Copy link

musjj commented Jul 20, 2024

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.

@simonlsk
Copy link

Correct, encountering the same issue.

@mweststrate
Copy link
Collaborator

PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants