Replies: 1 comment 11 replies
-
I think your best bet is annotating the payload creator instead: export const myAction = createAsyncThunk(
ACTIONS.MY_ACTION,
/** @type {import("@reduxjs/toolkit").AsyncThunkPayloadCreator<any, ParamType, { state: AppState }>}
async (params, { getState }) => {
const state = getState() // returns type `AppState`
// ...
},
); |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to write types with JSDoc for an action created with
createAsyncThunk
, but I can't find a way to get the correct return type forgetState
. I get the expected typeParamType
forparams
butgetState
always returnunknown
:As far as I know, what I pass seems correct.
AppState
is an object, and I also tried with dummy objects and strings to be sure it was not the problem, but I still getunknown
.I'm aware of the documentation of Redux usage with TS, but I don't use TS, and I can't understand why writing the type like this works for everything but the custom
ThunkApiConfig
.Beta Was this translation helpful? Give feedback.
All reactions