title: Why is my reducer returning undefined, React TypeScript
body: <p>I am trying to setup my <code>Redux</code> store with React and <code>TypeScript</code> but it gives me an error that my <code>auth</code> reducer is <code>undefined</code>.</p>
  
  <p>This is my <strong>store.ts</strong>:</p>
  
  <pre><code>import {Action, applyMiddleware, combineReducers, compose, createStore} from 'redux';
  import { auth, IAuthState } from './Auth/reducer';
  import { general, IGeneralState } from './General/reducer';
  
  export interface IAppState {
      auth: IAuthState;
      general: IGeneralState;
  }
  
  export const rootReducer = () =&gt; combineReducers({
          auth: auth,
          general: general,
  });
  
  const store = createStore&lt;IAppState, Action&lt;any&gt;, {}, {}&gt;(
      rootReducer(),
      (window as any).__REDUX_DEVTOOLS_EXTENSION__ &amp;&amp;
      (window as any).__REDUX_DEVTOOLS_EXTENSION__()
  );
  
  export { store };
  </code></pre>
  
  <p>This is my <strong>auth reducer</strong>:</p>
  
  <pre><code>import { User } from '../../interfaces/user.interface';
  import { AuthActionTypes } from './actions';
  
  export interface IAuthState {
      user: User;
      authenticated: boolean;
  }
  
  const initialState: IAuthState = {
      user: null,
      authenticated: true,
  };
  
  export const auth = (state: IAuthState = initialState, action: any): IAuthState =&gt; {
      switch (action.type) {
          case AuthActionTypes.Setuser:
              const { User } = action.payload;
  
              return {
                  ...state,
                  user: User
              };
  
          case AuthActionTypes.Logout:
  
              return {
                  ...state,
                  user: null,
                  authenticated: false,
              };
      }
  };
  </code></pre>
  
  <p>It gives me the error:</p>
  
  <blockquote>
    <p>Uncaught Error: Reducer "auth" returned undefined during
    initialization. If the state passed to the reducer is undefined, you
    must explicitly return the initial state. The initial state may not be
    undefined. If you don't want to set a value for this reducer, you can
    use null instead of undefined.</p>
  </blockquote>