title: Typescript Object is possibly null even inside an if statement checking that the object is not null
body: <p>I'm trying to access a property inside of an object inside of an array based on a provided index, and even though I check for that object not to be null, typescript still complains that it could be null.</p>
  <p>Also &quot;selectedIndex&quot; is actually a react state in my project.</p>
  <pre><code>const arrayOfObjects: {bar:{baz: string; qux: string;}}[] = [{bar: {baz: 'value', qux: 'value'}}];
  
  let selectedIndex: number = 0; //can be changed
  
  if (arrayOfObjects[selectedIndex].bar !== null) {
    doSomethingWith(arrayOfObjects[selectedIndex].bar.baz);
    // here there will be a typescript error saying that &quot;bar&quot; Object is possibly null
  }
  </code></pre>
  <p>Any idea?</p>