Wrong typing using combine middleware #2953
-
Bug DescriptionI'm encountering an issue with the
In this example Is it an issue with the typing or is it better to change the pattern and do not call action within another action of the same store ? Reproduction Link |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
That's how By the way, you could do this: https://tsplay.dev/WKJqzm import { createStore } from "zustand/vanilla";
import { combine } from "zustand/middleware/combine";
const exampleStore = createStore(
combine({ count: 0 }, (set, get) => {
const setCount = (count: number) => set({ count });
return {
setCount,
sideEffectFunc: () => {
setCount(10);
},
};
}),
);
exampleStore.getState().sideEffectFunc(); |
Beta Was this translation helpful? Give feedback.
That's how
combine
works. We can't recursively define types, soget()
type is only to return the first part.By the way, you could do this: https://tsplay.dev/WKJqzm