Skip to content
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

Typescript: action type parameter for Store, Dispatch, etc. #2643

Closed
samfrances opened this issue Oct 5, 2017 · 1 comment
Closed

Typescript: action type parameter for Store, Dispatch, etc. #2643

samfrances opened this issue Oct 5, 2017 · 1 comment

Comments

@samfrances
Copy link

samfrances commented Oct 5, 2017

Looking at the Typescript typings for Redux, it looks like there is no built-in way to type check calls to dispatch, etc. This looks like something that could be improved. For example you could envisage a store definition that looks something like the following:

interface Store<S, A extends Action = Action> {
  dispatch: Dispatch<S, A>;
  getState(): S;
  subscribe(listener: () => void): Unsubscribe;
}

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

Then, with appropriate modifications elsewhere, you could something like the following:

type MyAppActions =
  | CreateTodo
  | DeleteTodo
  | UpdateTodo;

const store = createStore<MyAppState, MyAppActions>(myReducer);

I would be interested to hear what you think of this as an idea. In particular, is this an idea that has already been considered and rejected in the past?

@samfrances
Copy link
Author

Looks like this is already being worked on: #2563

Good to see.

@reduxjs reduxjs deleted a comment from nenadalm Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant