ThunkAction is not assignable to parameter of type 'AnyAction'.
See original GitHub issueBug Report
Package name / version
redux-thunk@2.4.1
Description
I am trying to use a simple method from my store:
store.dispatch(ThunkAction);
It is working on run time, but I am receiving an error message on Typescript:
TS2345: Argument of type 'ThunkAction<Promise<AuthorizationDto | null>, State, unknown, SetAuthorizationAction>' is not assignable to parameter of type 'AnyAction'. Property 'type' is missing in type 'ThunkAction<Promise<AuthorizationDto | null>, State, unknown, SetAuthorizationAction>' but required in type 'AnyAction'.
I already tried to import the extend-redux like that:
import 'redux-thunk/extend-redux';
But the problem is the run time does not find file =S.

I already tried every single solution that’s I found on the previous issues, but non of them worked for me.
Steps to reproduce
- Install the redux-thunk using “npm install”
- Create a ThunkAction
- Call the
store.dispatch(ThunkAction) - See typescript Type error
Expected behavior
No error message from typescript when using store.dispatch(ThunkAction)
Environment
- OS: macOS Monterey 12.3.1
- Node/npm version: node v16.14.2 / npm 8.5
- Platform: React Native iOS/Android
Issue Analytics
- State:
- Created a year ago
- Reactions:16
- Comments:34 (19 by maintainers)
Top Results From Across the Web
Argument of type 'ThunkAction' is not assignable to parameter ...
Firstly: So your thunk not firing any other action can only have one meaning: The other calls to dispatch are most likely never...
Read more >TIPS react - Is not assignable to parameter of type 'AnyAction'
Salut les curieux, les curieusesQuand on travaille avec react, redux, et le redux toolkit, on peut tomber sur des cas tricky qui peuvent ......
Read more >How to dispatch a thunk with TS? : r/typescript - Reddit
argument of type "(dispatch: DispatchType) => void" is not assignable to parameter of type "AnyAction". The fetchAllProducts code
Read more >How to Use Thunks with Redux Toolkit and TypeScript
If we want to use rejectWithValue we need to define return-type and payload creator argument type as well. Adding Thunks to Slices#. Now,...
Read more >Usage With TypeScript - Redux
Since these are actual variables, not types, it's important to ... which takes the type of the action.payload field as its generic argument....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
FWIW, I believe the reason this is coming up as an issue with react-redux v8 is because the v7
useDispatch()was typed as:The first function overload means you can dispatch literally anything (as a workaround for
redux-thunk).But in v8 it’s now typed as:
which only allows for
Actionobjects.So this issue isn’t “new” it’s just been masked by the loose types in the old
react-reduxtype definitions.That’s just background for why this is coming up now. If you’re hitting this error now as a user you should either:
import 'redux-thunk/extend-redux'in a regular TypeScript file because they think you’re trying to import JavaScript so you can either:import type {} from 'redux-thunk/extend-redux'/// <reference types="redux-thunk/extend-redux" />in a.d.tsfile that’s included in your type-checkingimport 'redux-thunk/extend-redux'in a.d.tsfile that’s included in your type-checking