title: typescript index signature that index optional properties
body: <p>I would like to declare something like this in typescript 3.5.3</p>
  
  <pre><code>interface User {firstName: string}
  interface Contacts {[index: string]: User | undefined}
  </code></pre>
  
  <p>Basically I would like typescript to warn me about the fact that the property I am trying to access is potentially undefined. Currently, that's not the case when I write this:</p>
  
  <pre><code>const contacts: Contact = {};
  const randomId = '1240astat0252';
  const user = contacts[randomId]; //typescript doesn't warn me about this being undefined
  </code></pre>
  
  <p><strong>edit:</strong> in the specific project I was working on I forgot to set <code>strict: true</code> in the tsconfig which would not raise an error for <code>user.firstName</code>. In the original state of the question, the answer is correct.</p>