Cannot dispatch action(createAsyncThunk): Argument of type 'AsyncThunkAction<number, number, {}>' is not assignable to parameter of type 'AnyAction'.
See original GitHub issueWhen I try to dispatch an action created with createAsyncThunk from the screen, I get an error and cannot resolve it. It should be the same as on the official page…
sample.ts
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
// First, create the thunk
export const fetchUserById = createAsyncThunk(
'users/fetchByIdStatus',
async (userId: number, thunkAPI) => {
return userId
}
)
index.tsx
import { useDispatch } from 'react-redux';
const dispatch = useDispatch<AppDispatch>();
useEffect(() => {
dispatch(fetchUserById(1))
});
error:
TS2345: Argument of type 'AsyncThunkAction<number, number, {}>' is not assignable to parameter of type 'AnyAction'.
version:
"@reduxjs/toolkit": "^1.8.2",
"react-redux": "^8.0.2",
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Argument of type 'AsyncThunkAction<any, void, {}>' is not ...
I have a createAsyncThunk function that fetches the user, but I cannot actually put it in the dispatch()... Argument of type 'AsyncThunkAction< ...
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 >Usage With TypeScript - Redux
For useDispatch , the default Dispatch type does not know about thunks or other middleware. In order to correctly dispatch thunks, you need...
Read more >Redux-Toolkit with Typescript. Cannot dispatch action created ...
Argument of type 'AsyncThunkAction<User, UserCredentials, {}>' is not assignable to parameter of type 'AnyAction'. Property 'type' is ...
Read more >Accessing Global State inside of Async Thunks with TypeScript
The payloadCreator argument to createAsyncThunk takes two arguments. The first is a single arg that receives data passed into the thunk's action creator ......
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
Yep. Folks, please make sure that you’re following the syntax shown in the docs!
@denisonepiece your code is
which is very different from what we show in the docs.
please follow the approach recommended in the docs and use
.concat
instead of spreading here, the spread waters down the types of the array elements beyond recognition