我正在将我的根化简器从javascript转换为打字稿,但是,我收到一个linting错误,说:
函数上缺少返回类型。 (@typescript-eslint/显式函数返回类型(
根化简器函数的正确返回类型应该是什么?谢谢。
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),
});
似乎您已经设置了规则"要求函数和类方法的显式返回类型",并且需要显式指定函数的返回类型。
组合化简器返回函数的类型为 Reducer<S, A>
,其中 S
代表应用程序状态。
首先,我建议您定义如下所示的应用程序状态
import { RouterState } from 'connected-react-router';
type AppState = {
sampleReducer: /* type of state, that sampleReducer accepts and returns */;
router: RouterState
}
然后你就可以输入根化简器
import { Reducer } from 'redux';
export default (historyObject: History): Reducer<AppState> => combineReducers({
sampleReducer,
router: connectRouter(historyObject),
});