export type Handlers = { [type: string]: (state: T, action: any) => T; }; export function createReducer(handlers: Handlers, initialState: S) { return (state: S = initialState, action: AnyAction) => { const handler = handlers[action.type]; if (handler) return handler(state, action); return state; }; }