输入Redux异步动作创建者

时间:2018-09-12 22:42:41

标签: typescript redux

我正在尝试键入此函数,但遇到麻烦

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在做什么。

出了什么问题?

0 个答案:

没有答案