title: How to debug TypeScript by printing the inferred variable type?
body: <p>Often TS fails for me because the type it infers is different from what I expect it to be. I could force typecast variables, but I'd prefer to figure out why TS isn't inferring the types correctly.</p>
  
  <p>Is there a way to print the type that TS believes a variable is?</p>
  
  <p>E.g.:</p>
  
  <pre><code>const obj = [
    { a: 'foo' },
    { b: 'bar' },
  ];
  
  printTsType(obj[0].a);
  </code></pre>
  
  <p>I would expect this to be the literal <code>'foo'</code>, but I think TS just infers <code>string</code>.</p>