-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Wrong AsyncThunkAction
args type when creating a thunk without args using create.asyncThunk
#4060
Comments
Thanks for the report! Oddly it seems like I messed up when making the types for create.asyncThunk - they should be identical to createAsyncThunk's but aren't. I've raised #4061 to fix this, but it's technically a breaking change so I'm waiting for confirmation whether it would be able to be in a less-than-major release. In the meantime, that PR will have a build made by CodeSandbox that should fix the issue if installed. edit: it'll be in the next release :) |
@EskiMojo14 I'm experiencing same issue with version 2.2.3. Very oddly, thunk type is inferred differently depending on how thunk is declared: as a part of reducers object, or separately. import { asyncThunkCreator, buildCreateSlice } from "@reduxjs/toolkit";
const createAsyncSlice = buildCreateSlice({
creators: {
asyncThunk: asyncThunkCreator,
},
});
type State = {};
const slice = createAsyncSlice({
name: "demo",
initialState: {} as State,
reducers: (create) => {
const standalone = create.asyncThunk(() => {});
return {
standalone,
/* ^^^
AsyncThunkSliceReducerDefinition<
State,
void, // <--- ✅
void,
PreventCircular<AsyncThunkConfig>
>
*/
inline: create.asyncThunk(() => {}),
/* ^^^
AsyncThunkSliceReducerDefinition<
State,
any, // <--- ❌
void,
PreventCircular<AsyncThunkConfig>
>
*/
inline_explicit: create.asyncThunk<void>(() => {}),
};
},
});
const { standalone, inline, inline_explicit } = slice.actions;
standalone(); // ok
inline(); // Expected 1 arguments, but got 0.
inline_explicit(); // ok Please see a reproduction playground. |
Sometimes thunks doesn't require any args.
When creating a thunk without args using
create.asyncThunk
, the action still expects one argument.Example
Codesandbox: https://codesandbox.io/p/sandbox/quirky-sunset-8qsxf4?file=%2Fsrc%2FcounterSlice.ts%3A20%2C1
The text was updated successfully, but these errors were encountered: