我正在尝试键入此函数,但遇到麻烦
function createAsyncAction(actionName: ActionNames, functionName: String) {
return function(
...params: any[]
): ActionCreator<ThunkAction<any, any, any, any>> {
return async function(dispatch, getState, client, any) {
dispatch({ type: `${actionName}_REQUESTING`, status: REQUESTING });
try {
let result = null;
if (client[functionName]) {
result = await client[functionName].apply(this, params);
}
dispatch({ type: `${actionName}_SUCCESS`, payload: result });
} catch (e) {
dispatch({ type: `${actionName}_FAILURE`, error: e.message });
}
};
};
}
我收到ActionCreator<ThunkAction<any,any,any,any>>
类型的错误。
这是错误
Type '(dispatch: any, getState: any, client: any, any: any) => Promise<any>' is not assignable to type 'ActionCreator<ThunkAction<any, any, any, any>>'.
Type 'Promise<any>' is not assignable to type 'ThunkAction<any, any, any, any>'.
Type 'Promise<any>' provides no match for the signature '(dispatch: ThunkDispatch<any, any, any>, getState: () => any, extraArgument: any): any'.
但是,我不明白为什么会发生此错误,可能是因为我不完全了解ThunkAction在做什么。
出了什么问题?