title: Type 'undefined' must have a '[Symbol.iterator]()' method that returns an iterator
body: <p>I am trying to convert my reducer from JS to typescript but I am getting a weird error that I have not been able to resolve. The error comes from using ellipsis for array deconstruction in the reducer <strong>[...state.messages]</strong>. Basically the code is as follows:
  Reducer:</p>
  
  <pre><code>import { HomeScreenAction } from '../actions';
  import { HomeState, User, Message } from '../types';
  import * as constants from '../constants';
  import { combineReducers } from 'redux';
  
  export function userState(state: HomeState = {}, action: 
  HomeScreenAction): HomeState {
  switch (action.type) {
  case constants.REQUEST_USER:
  case constants.RECEIVE_USER:
    return { user: action.user };
  default:
    return state;
  }
  }
  
  
  export function messagesState(state: HomeState = {}, action: 
  HomeScreenAction):HomeState {
  switch (action.type) {
  case constants.REQUEST_MESSAGES:
  case constants.RECEIVE_MESSAGES:
    return { messages: action.messages };
  case constants.Test1:
    return{ ...state, user: action.payload};
  case constants.Test2:
    return {...state, messages:[ ...state.messages, action.payload ]};
  default:
    return state;
  }
  }
  
  const rootReducer = combineReducers({
  userState,
  messagesState
  });
  
  export default rootReducer;
  </code></pre>
  
  <p>types:</p>
  
  <pre><code>export interface HomeState {
  user?: User;
  messages?: Message[];
  }
  export interface Test1 {
  type: typeof constants.Test1
  payload: User
  }
  
  export interface Test2 {
  type: typeof constants.Test2
  payload: Message
  }
  </code></pre>
  
  <p>and the tsconfig.js:</p>
  
  <pre><code>  "compilerOptions": {
  /* Basic Options */
  "target": "es6",                          
  "watch": false,
  "module": "commonjs",
   "lib":  [ "dom", "es6", "es2015" , "dom.iterable"],
  // "allowJs": true,
  // "checkJs": true,
  "jsx": "react",
  // "declaration": true,
  "sourceMap": true,
  // "outFile": "./",
  "outDir": "./lib",
  
  "strict": true
  
  },
  "include": ["./src/"]
  }
  </code></pre>
  
  <p>I have tried different libs such as es2015 and es5 but still I get an error for </p>
  
  <pre><code>[...state.messages]
  </code></pre>
  
  <p>any help would be very much appreciated. </p>