The issue here is that the createAsyncThunk
function does not know the type of your store's state. You can set the type by supplying generics to the function.
interface MyState {
LoginPageReducer: {
token: string;
}
}
export const redirectUser = createAsyncThunk<any, number, {state: MyState}>(
"login/redirectUser",
async (id, { getState, requestId }) => {
const token = getState().LoginPageReducer.token;
}
);
Now id
has type number
, getState()
has type MyState
, and token
has type string
.
You can see more of the details for these typings here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…