title: TypeScript React - useReducer with Array of Objects in Interface
body: <p>I've created the following component:</p>
  <pre><code>import React, {useReducer} from 'react'
  
  type ACTION_TYPE = | {type: 'SET_USER', userId: number} | {type: 'DELETE_USER', userId: number, deleteMessages: boolean}
  
  interface User { 
      id : number; 
      name? : string; 
      surname?: string; 
      hasDiscount?: boolean;
  }
  
  
  const myReducer = (state : typeof initialState, action : ACTION_TYPE) =&gt; { 
      switch (action.type) {
          case 'DELETE_USER':
              return {users: [...state.users, {id: action.userId}]}
          default:
              return state;
      }
  }
  
  const initialState = {
      users : []
  }
  
  const TestingComponent : React.FC = () =&gt; { 
  
      const [state, dispatch] = useReducer(myReducer,initialState)
  
  
      return (
  &lt;div&gt;&lt;/div&gt;
      )
  }
  
  export default TestingComponent
  </code></pre>
  <p>I'm getting an error on my <code>useReducer</code> - <code>No overload matches this call. Overload 1 of 5, '(reducer: ReducerWithoutAction&lt;any&gt;, initializerArg: any, initializer?: undefined): [any, DispatchWithoutAction]', gave the following error. Argument of type '(state: typeof initialState, action: ACTION_TYPE) =&gt; { users: { id: number; }[]; }' is not assignable to parameter of type 'ReducerWithoutAction&lt;any&gt;'. Overload 2 of 5, '(reducer: (state: { users: never[]; }, action: ACTION_TYPE) =&gt; { users: { id: number; }[]; }, initialState: never, initializer?: undefined): [never, Dispatch&lt;ACTION_TYPE&gt;]', gave the following error. Argument of type '{ users: never[]; }' is not assignable to parameter of type 'never'.ts(2769)</code></p>
  <p>I'm not sure how to interpret this though - I've also tried creating the following interface</p>
  <pre><code>interface USER_STATE { 
      users: [User]
  }
  </code></pre>
  <p>and using it in <code>myReducer</code> to define the type of <code>state</code> - but this also doesn't work.</p>