redux: Dispatch interface should not be generic
Do you want to request a feature or report a bug?
A small typings refactor.
What is the current behavior?
The Dispatch
interface is currently generic, when it doesn’t need to be, the generic type is never used. I don’t know if there is a particular reason why it has been done the way but it isn’t documented either.
As I mentioned, I’m not sure if there is a reason why it has been done this way but I feel that it should either be changed or documented.
What is the expected behavior?
There should be no generic.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (4 by maintainers)
Commits related to this issue
- refactor(types): fix type issue with Dispatch, see https://github.com/reactjs/redux/issues/2380 — committed to connorwyatt/React-Todo-UI by connorwyatt 7 years ago
- Merge pull request #2380 from reduxjs/prepare-codegen-1.1 Codegen v1.1 integration — committed to brandoncroberts/redux by msutkowski 2 years ago
Folks, and what would you think of marking the existing generic interface as deprecated, and placing a new one with the correct signature nearby? That will not break the backwards compatibility for the existing libraries.
Typescript’s Do’s and Don’ts page says right near the top to never have unused type parameters
Not sure if this is a known exception to that rule, but the linked FAQ explains some problems that can occur from this.
Adding a comment near the definition is the best we can do now without introducing a breaking change.
With generic defaults introduced in TS 2.3 we can update it as follows:
This way users won’t have to set a parameter explicitly every time they use
Dispatch
type.However, this would still be a breaking change. The
next
branch is a good place for stuff like this.More like this actually: