-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Dispatch<> type parameter provides a type-safe dispatch() function #84
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
Comments
Hello, |
Sorry for not being clear! Suppose I have this action type:
And a connected component dispatches an action:
The important thing is the type of the dispatch parameter: And because by that time the argument to the If I knew how to type the dispatch function correctly and had updated to redux 4, this wouldn't have happened. Anyway, my point was to add this information to your guide, because it aims to be complete, and this is a gap that I found and think is worth filling. |
The important part to highlight here is that it's useful in cases when you dispatch an action object on the dispatch call site as opposed to using action-creators defined in a separate reusable module. |
I haven't looked deeply into the idea about action creators, they seem appealing - but so far I didn't feel a need for them and used plain old action objects. Thanks for pointing them up! 👍 I just wanted to raise attention to the two places where you're giving an example with I would have sent a PR but initially my idea was to discuss a more throughout example about the way I was doing the things, so I did not send one. Now that such discussion is unneded and this issue will be closed shortly, I might as well send one, but for a such small change I guess it's not worth it. |
@BoostIO funded this issue with $20. Visit this issue on Issuehunt |
@loadbalance-sudachi-kun funded this issue with $256. Visit this issue on Issuehunt |
@piotrwitek has started working. Visit this issue on Issuehunt |
@piotrwitek has submitted output. Visit this issue on Issuehunt |
@piotrwitek has rewarded. Visit this issue on Issuehunt |
Added a new section explaining the concept of type-safe Dispatch and also entire concept of typing the connect mapper functions and the connect itself |
Redux 4 introduces a type-safe dispatch function, which means that the argument passed to
dispatch()
must be the type of the firstDispatch<Action>
parameter. If I knew this ealier, it would save me two hours debugging and searching why dispatch() with an incomplete action doesn't trigger an error :) I think this deserves its section in the guide.The text was updated successfully, but these errors were encountered: