import { Action , AnyAction , Reducer } from 'redux' ; import { SubReducer } from './types' ; param firstChildReducer param otherChildReducers export default function chainReducers < S = any , A extends Action = AnyAction > ( firstChildReducer , ... otherChildReducers ) { if ( ! firstChildReducer ) { throw new Error ( 'chainReducers() needs at least one reducer.' ) ; } if ( otherChildReducers . length === 0 ) { return firstChildReducer ; } return function chainedReducer ( state , action ) { const nextState = firstChildReducer ( state , action ) ; return otherChildReducers . reduce ( ( s , reducer ) => reducer ( s , action ) , nextState ) ; } ; }