redux-toolkit: Property 'type' is missing in type 'AsyncThunkAction' but required in type 'AnyAction'.
TS2345: Argument of type ‘AsyncThunkAction<TicketEntity[], void, {}>’ is not assignable to parameter of type ‘AnyAction’. Property ‘type’ is missing in type ‘AsyncThunkAction<TicketEntity[], void, {}>’ but required in type ‘AnyAction’.
package.json
"@reduxjs/toolkit": "1.7.1",
"react": "17.0.2",
"react-redux": "7.2.6",
store.ts
...
export const store = configureStore({
reducer: {
[EntityStoreName.Oem]: oemReducer,
[EntityStoreName.Ccvs]: ccvsState.reducer,
[EntityStoreName.CloudConnections]: cloudConnectionsState.reducer,
[EntityStoreName.ChangeRequests]: changeRequestsState.reducer,
[EntityStoreName.Locations]: locationsState.reducer,
[EntityStoreName.Organizations]: organizationsReducer,
[EntityStoreName.Tickets]: ticketsState.reducer,
[EntityStoreName.TicketComments]: ticketCommentsState.reducer,
[EntityStoreName.TicketAttachments]: ticketAttachmentsState.reducer,
[StoreName.Session]: sessionReducer,
[StoreName.Modal]: modalState.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
},
}),
});
export const persistor = persistStore(store);
export type AppState = ReturnType<typeof store.getState>;
repository.ts
export const getTicketsList = createAsyncThunk(
`${EntityStoreName.Tickets}/getList`,
(_, { signal }): Promise<TicketEntity[]> => {
const cancelToken = cancelationSubscribe(signal);
return apiRequestCall<TicketEntity[]>({
params: {
method: 'GET',
apiVersion: ApiVersion.V1,
resource: ApiResource.Tickets,
cancelToken,
},
});
}
);
Type issue:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 21 (6 by maintainers)
Commits related to this issue
- Fix error https://github.com/reduxjs/redux-toolkit/issues/1854 — committed to flrnd/nextUI by flrnd 2 years ago
- Redux toolkit (#49) * Clean comment * Add redux package * It was already added * Add redux types * Refactor. Move hooks to /lib and update files * Add types * Add store config * ... — committed to flrnd/nextUI by flrnd 2 years ago
I have the same issue, and no duplicated redux version
Hey there, Just in case, I had the same problem with 8.0.2 and solved it adding the type in the declaration like this:
const dispatch = useDispatch<AppDispatch>();
Most likely you have two conflicting versions of
redux
somewhere in yournode_modules
.4.0.x
and4.1.x
are not compatible on a type level (and generally you should only have one redux version). You can search those withnpm ls redux
oryarn why redux
.@flrnd please follow the TypeScript QuickStart and define a typed
useAppSelector
hook.sorry, I had 1.7.2 toolkit version, it’s fixed in 1.8.0
nope I’ll try to recreate it a bit later in a simpler project