zustand: subscribeWithSelector break types with Typescript
Hello,
I have issue with the new middleware subscribeWithSelector
I dont’t understand why…
Previously I used ramda pipe
function to combine my differents middlware in a more clean way, but the same error…
More generaly, Zustand lack of typescript examples / documentation, I’m often struggled with Type error using zustand
Could you help me ? Thanks !
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 21 (13 by maintainers)
That said, before looking for better solution in general, I would like to find a specific solution to your issue.
How does this help?
~Hm, maybe we should remove
Omit<..., 'subscribe'>
.~ No, it errors… Okay, if I remove deprecated signature, it can.Hi, thanks for raising this.
Typing middleware is really hard and almost impossible to infer type nicely. I agree docs and examples are missing. Especially, combining mutiple middlewares with types requires some rules and patterns.
And, we are still seeking… So, appreciate for this example.
The rule of thumb (for now):
devtools
,subscribeWithSelector
,persist
, andimmer
.State
type near the leaf.(Typing root
create
is trickier.)Hope it helps.