Skip to content

Wrong typing using combine middleware #2953

Discussion options

You must be logged in to vote

That's how combine works. We can't recursively define types, so get() type is only to return the first part.

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();

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@simon-milleto
Comment options

@dai-shi
Comment options

Answer selected by simon-milleto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants