Typescript setState
accepts a partial state, even if the replace
option is enabled
#2578
Answered
by
dai-shi
Yonom
asked this question in
Bug report
-
The Example: type MyStore = { foo: string; bar: string };
const useMyStore = create<MyStore>()(() => ({ foo: "hello", bar: "world" }));
useMyStore.setState({}, true); // <- this does not produce an error, even though the new value is invalid Suggested change in type SetStateInternal<T> = {
_(
partial: T | Partial<T> | { _(state: T): T | Partial<T> }['_'],
- replace?: boolean | undefined,
+ replace?: false | undefined,
): void
+ _(
+ partial: T | { _(state: T): T }['_'],
+ replace: true,
+ ): void
}['_'] |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jun 4, 2024
Replies: 1 comment 3 replies
-
I agree it's a reasonable fix. Would you like to open a PR please? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Yonom
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I agree it's a reasonable fix. Would you like to open a PR please?
I don't know if it causes some troubles in some edge cases.