Argument of type 'StateCreator<..., [], [["zustand/devtools", never], ["zustand/persist", ...]]>' is not assignable to parameter of type 'StateCreator<..., [], [never, unknown][]>'. #2168
-
Hi everyone, I was implementing Zustand to my new project but I could not get it to work (including the example given by the documents). It gives me this error (I took out devtools to make it a bit easier to read):
The code I tried to implement: const useBearStore2 = create<BearState>()(
persist(
(set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
{ name: "bearStore" }
)
); I tried another method without workaround docs const useBearStore = create<BearState, [["zustand/persist", BearState]]>(
persist(
(set) => ({
bears: 0,
increase: (by) => set((state) => ({ bears: state.bears + by })),
}),
{ name: "bearStore" }
)
); It gave me this error:
I could not replicate the issue on TS playground: link This is my repo: link Step to reproduce:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 7 replies
-
I digged a bit more but I found another similar problem: #2164 --> Potential duplicates |
Beta Was this translation helpful? Give feedback.
-
I think i has the similar problem and I tried to completely copy the code from the offical doc import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
type State = {
count: number
}
type Actions = {
increment: (qty: number) => void
decrement: (qty: number) => void
}
export const useCountStore = create<State & Actions>()(
immer((set) => ({
count: 0,
increment: (qty: number) =>
set((state) => {
state.count += qty
}),
decrement: (qty: number) =>
set((state) => {
state.count -= qty
}),
}))
) But typescript complains there is an error |
Beta Was this translation helpful? Give feedback.
-
Hey! I think it might be a problem with VSCode, or with the configuration from tsconfig, or eslint, a NextJS config, I don't know. |
Beta Was this translation helpful? Give feedback.
-
Hey peeps, there's a fix for that #2170. BTW, would you mind trying the local instructions (https://ci.codesandbox.io/status/pmndrs/zustand/pr/2170/builds/434064)? |
Beta Was this translation helpful? Give feedback.
Hey peeps, there's a fix for that #2170. BTW, would you mind trying the local instructions (https://ci.codesandbox.io/status/pmndrs/zustand/pr/2170/builds/434064)?