title: TS2538 Type 'undefined' cannot be used as an index type. when check assigned to variable
body: <p>I get TS error:</p>
  
  <blockquote>
    <p>TypeScript error: Type 'undefined' cannot be used as an index type.  TS2538</p>
  </blockquote>
  
  <p>For this simple function (getting object from array based on provided index):</p>
  
  <pre class="lang-js prettyprint-override"><code>const myArr: Array&lt;object&gt; = [{name: 'John'}, {name: 'Tom'}]
  
  function getData(index?: number) {
      const isIndex : boolean = typeof index !== 'undefined';
  
      return isIndex ? myArr[index] : {};
  }
  </code></pre>
  
  <p>What's more mysterious for me is that when I change it to:</p>
  
  <pre><code>function getData(index?: number) {
      return typeof index !== 'undefined' ? myArr[index] : {};
  }
  </code></pre>
  
  <p>Everything works like a charm - why?</p>