pmndrs / zustand

🐻 Bear necessities for state management in React

Home Page:https://zustand-demo.pmnd.rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type problem with persist

nerkn opened this issue · comments

Summary

Code I've written for 4.4.4 which is working very fine, gave typescript error on 4.4.5

argument of type 'StateCreator<useCartType, [], [["zustand/persist", useCartType]]>' is not assignable to parameter of type 'StateCreator<useCartType, [], [never, unknown][]>'. Type 'StateCreator<useCartType, [], [["zustand/persist", useCartType]]>' is not assignable to type '{ $$storeMutators?: [never, unknown][] | undefined; }'. Types of property '$$storeMutators' are incompatible. Type '[["zustand/persist", useCartType]] | undefined' is not assignable to type '[never, unknown][] | undefined'. Type '[["zustand/persist", useCartType]]' is not assignable to type '[never, unknown][]'. Type '["zustand/persist", useCartType]' is not assignable to type '[never, unknown]'. Type at position 0 in source is not compatible with type at position 0 in target. Type 'string' is not assignable to type 'never'.

Link to reproduction

https://github.com/nerkn/ecommerce-Frontend/blob/main/src/hooks/useCart.ts

Check List

  • I've already opened a discussion before opening this issue, or already discussed in other media.
    comment of muammed

https://stackoverflow.com/questions/77402109/zustand-and-typescript-persist-function-cannot-be-implemented

Please include a minimal reproduction.

Please check this if you're filing an issue regarding TypeScript.

  • I've read the typescript guide, in particular that create is to be used as create<T>()(...) and not create<T>(...).

Can concur, experiencing the same issue with using the immer middleware (immer@10.0.3) in v4.4.5. No problem with v4.4.4.

I was about to submit this on Tuesday but couldn't reproduce it. Since wednesday was holiday, I just got around to it. What a coincidence that you beat me by 39 minutes.

Here is my reproduction:
https://codesandbox.io/p/sandbox/vibrant-bash-prcf7q?file=%2Fsrc%2Fstore.ts%3A21%2C6

It only happens with "moduleResolution": "bundler", in tsconfig.

I have the same issue