better support for typescript in subscribe? #600
Replies: 1 comment
-
It turns out it's not possible with the current API and the current TypeScript. #555 A workaround for you is to create a helper function. const subscribeWithSelector = <T extends State, U>(
store: StoreApi<T>,
selector: (state: T) => U,
listener: (slice: U) => void
) => store.subscribe(listener, selector); See the working example: https://codesandbox.io/s/inspiring-babycat-vmucu?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm curious if anyone has a way to get better types for the state within the subscribe function. Seems to me that this should work similar to the hook where the selector you provide helps type what is returned, but at least in my experience the state is only just
object
.Beta Was this translation helpful? Give feedback.
All reactions