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 types seem off for ThunkAction/ThunkDispatch #280

Closed
ORESoftware opened this issue Mar 3, 2020 · 2 comments
Closed

typescript types seem off for ThunkAction/ThunkDispatch #280

ORESoftware opened this issue Mar 3, 2020 · 2 comments

Comments

@ORESoftware
Copy link

The ThunkAction should return a function that takes dispatch (a known type of ThunkDispatch) as it's first argument:

Screenshot from 2020-03-03 11-30-40

the problem here is that dispatch() does not return a promise according to the types, but it should/does.

@laat
Copy link
Contributor

laat commented Mar 3, 2020

This should work:

import { Action } from "redux";
import { ThunkAction } from "redux-thunk";
const logout = (): ThunkAction<any, any, any, Action> => dispatch => {
  dispatch(() => Promise.resolve()).then();
}

Also, look at the comments in #213 and #231

Redux Toolkit "Advanced Tutorial" shows a recommended approach for thunks in TS

@laat
Copy link
Contributor

laat commented Mar 3, 2020

The Redux docs "Usage with TypeScript" documents this

@timdorr timdorr closed this as completed Mar 4, 2020
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

3 participants