Closed
Description
Type inference breaks when using store.subscribe
with a selector.
import createStore from "zustand/vanilla";
const store = createStore(() => ({
hello: "world"
}));
store.subscribe((state) => {
// 👍 state type is inferred here
console.log(state.hello);
});
store.subscribe(
(state) => {
// 💥 state type "unknown" here
console.log(state.hello);
},
({ hello }) => ({ hello })
);
Here's a Codesandbox.
Is this a known limitation?