Reputation: 3860
I am convert my root reducer from javascript to typescript, however, I am getting a linting error saying:
Missing return type on function. (@typescript-eslint/explicit-function-return-type)
What should be the proper return type for my root reducer function? Thanks.
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),
});
Upvotes: 3
Views: 2032
Reputation: 11848
It seems that you've set the rule "Require explicit return types on functions and class methods" and you're required to specify return types for functions explicitly.
combineReducer return function of type Reducer<S, A>
, where S
is standing for app state.
First of all I suggest you to define app state like below
import { RouterState } from 'connected-react-router';
type AppState = {
sampleReducer: /* type of state, that sampleReducer accepts and returns */;
router: RouterState
}
Then you'll be able to type root reducer
import { Reducer } from 'redux';
export default (historyObject: History): Reducer<AppState> => combineReducers({
sampleReducer,
router: connectRouter(historyObject),
});
Upvotes: 3