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.

Dispatch interface

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

Most upvoted comments

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

Generics Don’t ever have a generic type which doesn’t use its type parameter. See more details in TypeScript FAQ page.

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:

interface Dispatch<S = any> {
  // ...
}

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:

export interface Dispatch<A extends Action> {
    (action: A): A;
}