question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot dispatch action(createAsyncThunk): Argument of type 'AsyncThunkAction<number, number, {}>' is not assignable to parameter of type 'AnyAction'.

See original GitHub issue

When 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:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, Jun 27, 2022

Yep. Folks, please make sure that you’re following the syntax shown in the docs!

1reaction
phryneascommented, Jun 27, 2022

@denisonepiece your code is

 middleware: (getDefaultMiddleware) => [
    ...getDefaultMiddleware({
      serializableCheck: {
        isSerializable: () => true,
      },
    }),
    saga,
  ],

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found