-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SetState & GetState Typescript declaration in create function arguments (bis) #45
Comments
The fix works fine with a very basic sample like this one : But I'm afraid that th fix is not enough because it is very easy to get a non working case. Imagine you have several stores, and imagine you want to do something generic on them. You will create a function that performs the "generic" things and then call that function for each store you have. This will lead you to create a generic function that encapsulates the zustand Just take a look at this really trivial sample in which we try to do something generic during store intialization : I hope you will agree with me that this sample code is trivial (10 lines of effective code), and it highlights the problem... In other words, as soon as you want to add even a thin layer over zustand for your own purpose in Typescript world, you meet that problem. I have put all this (trivial) code on codesandbox : https://codesandbox.io/s/j2nys |
Another way to present the problem is that today, it is not possible to extend zustand using typescript. Because anybody that would like to extend zustand will quickly have to create a generic function that encapsulates zustand And the export default function create<TState extends State>(createState: keyof TState extends never ? StateCreator<State> : StateCreator<TState>): [UseStore<TState>, StoreApi<TState>]; |
I can't find a way to allow extending |
#49 fixes this issue a far as I can see. I close the current issue. Thanks a lot. |
I opened an issue #32 a few weeks ago. The #35 pull request was supposed to fix the problem, but as far as I can see, it doesn't.
The text was updated successfully, but these errors were encountered: