useReducer’s initialState is typed as never?

I also struggled with this problem. The best way to prevent bugs seems to me to add the State Interface as the return type of the reducer. Then you see the type errors inside the reducer instead on the useReducer line.

like this:

function reducer(state: IState, action: IFluxAction): IState {
   // reducer code
   // type errors are visible here 

Leave a Comment