-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(middleware): revert types of redux middleware #1206
Conversation
src/middleware/redux.ts
Outdated
reducer: (state: T, action: A) => T, | ||
initialState: T | ||
) => StateCreator<Write<T, ReduxState<A>>, Cms, [['zustand/redux', A]]> | ||
|
||
declare module '../vanilla' { | ||
interface StoreMutators<S, A> { | ||
'zustand/redux': WithRedux<S, A> | ||
'zustand/redux': WithRedux<S, A & Action> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't so sure, but is this what you mean? @devanshj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
Bonus if you use Cast
instead. To see the difference write a store with redux middleware, hover on the dispatch
function, you'll see in the action parameter there's an extra and redundant & Action
, but if you use Cast
the action type will be as it is. If you want I can also explain how Cast
works for the record.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I know what Cast does, but I don't get how it improves tooltip. Can this be explained with TS playground?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go https://tsplay.dev/wXjKVm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I understand this one, and why Cast
is preferable.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b11f3ac:
|
Size Change: -329 B (-1%) Total Size: 29.1 kB
ℹ️ View Unchanged
|
I kinda like what I did. In my mental model, the So, unless we have obvious limitations like quickinfo one, I'd go with this. |
Yeah that mental model is not bad, so yeah it's okay to go with this. |
In #1144, I made some types loosen, which includes not only
State
but alsoAction
in the redux middleware. @devanshj pointed out that it can cause misusage with the combination ofredux
anddevtools
middleware.So, I'm convinced to revert the
Action
part of the change.