我有一个createAsyncThunk
操作,想访问工具包中的getState
。我不确定如何在typescript中转换getState
类型:
export const getInitialDatapoints = createAsyncThunk(
'userSlice/getInitDatapoints',
async (args, { getState as AppState }) => {
const geoData = await getLocationData();
const googleData = getState().userSlice;
const response = await updateUserData(1);
return response.data;
}
);
其中AppStore
为:
export type AppState = ReturnType<typeof store.getState>;
我得到这个错误:
Property 'AppState' does not exist on type 'GetThunkAPI<{}>'
有人能帮助解决这个问题吗?
1条答案
按热度按时间toiithl61#
解构对象时不能Assert类型。另外,在将
getState
Assert为AppState
之前,需要调用getState
。您可以改为执行以下操作: