【问题标题】:React Redux Thunk actions with typescript使用 typescript 反应 Redux Thunk 动作
【发布时间】:2021-04-04 12:31:38
【问题描述】:

我试图了解从我的操作函数返回的合适类型是什么: (将actions函数分成两个函数的结构是有意的)

type.ts:

export interface JsxActions {
  init: (params: IProject, filterSearch ? : ISearch[]) => any;
}

export interface ApiFunc {
  initCostDashboard: (params: IProject, filterSearch ? : ISearch[]) => any;
}

actions.ts:

export let jsxActions: JsxActions | Partial < JsxActions > = {};

jsxActions.init = function(params: IProject, filterSearch ? : ISearch[]): /* What will be return type */ {
  return function(dispatch: Dispatch < AppActions > , getState: () => AppState) {
    return api.initCostDashboard(params, filterSearch)(dispatch, getState);
  };
};

export let api = {}
as ApiFunc;
api.initCostDashboard = function(params: IProject, filterSearch ? : ISearch[]) /* What will be return type */ {
  return function(dispatch: Dispatch < AppActions > , getState: () => AppState) {
    // ...Do something
  }
}

谢谢

【问题讨论】:

    标签: reactjs typescript react-typescript


    【解决方案1】:

    您可能需要查看https://redux.js.org/recipes/usage-with-typescript#type-checking-redux-thunks 以了解如何明确返回返回 ThunkActions 的 init 和 initCostDashboard 的返回类型。

    【讨论】:

      猜你喜欢
      • 2016-06-12
      • 2018-01-18
      • 2018-09-22
      • 2020-04-24
      • 2019-03-23
      • 2018-08-31
      • 1970-01-01
      • 2019-11-14
      • 2021-01-20
      相关资源
      最近更新 更多