-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
refactor(types/actions): allow type-setting args on ActionCreator #3797
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
Conversation
Deploy preview for redux-docs ready! Built with commit a30fe8f |
I'm not quite sure if there are tests for TS typings. Please let me know if I can add those in, if necessary. Thanks |
Because it's a rest parameter, this is enforcing a uniform type for every argument. However, it would be possible to support non-uniform types like so: interface ActionCreator<A, P extends any[] = any[]> {
(...args: P): A
} That would allow you to separately type each argument. The counter-point would be that you must pass an array type, such as |
👏 That's a very nice idea! I'd guess it could look easier to the eye, having it declared as So we could even have Thanks for the review. |
OK, I'm cool with this as-is. Thanks! |
…duxjs#3797) Former-commit-id: 856e6e3 Former-commit-id: 55bf4e3
…duxjs#3797) Former-commit-id: 856e6e3 Former-commit-id: 55bf4e3
…duxjs#3797) Former-commit-id: 856e6e3 Former-commit-id: 55bf4e3
Following up #3541 (comment)
We are allowing Action creators to be typed by declaring their return type as well as the argument type so function calls keep the expected parameter types.
name: "allow type-setting args on ActionCreator"
about: improving type declarations on Redux
PR Type
Does this PR add a new feature, or fix a bug?
It sort of adds a new feature, but it's opt-in for the type usage defaulting to the same as the previous behaviour.
Why should this PR be included?
Allow developers to use Redux provided typings in order to implement ActionCreators
Checklist
New Features
What new capabilities does this PR add?
What docs changes are needed to explain this?
Bug Fixes
What is the current behavior, and the steps to reproduce the issue?
What is the expected behavior?
How does this PR fix the problem?