Redux根减速器的返回类型

时间:2019-07-18 00:35:02

标签: typescript redux connected-react-router

我正在将我的root reducer从javascript转换为打字稿,但是,我收到了以下提示:

  

缺少函数的返回类型。   (@ typescript-eslint / explicit-function-return-type)

我的root减速器函数应该正确的返回类型是什么?谢谢。

import { History } from 'history';
import { combineReducers } from 'redux';
import { connectRouter } from 'connected-react-router';
import sampleReducer from './sampleReducer';

export default (historyObject: History) => combineReducers({
  sampleReducer,
  router: connectRouter(historyObject),
});

1 个答案:

答案 0 :(得分:1)

似乎您已设置规则“ Require explicit return types on functions and class methods”,并且需要明确指定函数的返回类型。

类型为return function

combineReducer Reducer<S, A>,其中S代表应用程序状态。

首先,我建议您定义如下的应用状态

import { RouterState } from 'connected-react-router';

type AppState = {
    sampleReducer: /* type of state, that sampleReducer accepts and returns */;
    router: RouterState
}

然后您将能够输入root reducer

import { Reducer } from 'redux';

export default (historyObject: History): Reducer<AppState> => combineReducers({
    sampleReducer,
    router: connectRouter(historyObject),
});