title: Get Typescript interface property type, given property name only
body: <p>I have a Typescript interface with many properties. Without any instance of this interface, I need to determine the type of a given property. </p>
  
  <pre class="lang-js prettyprint-override"><code>export interface Data {
    foo: string;
    bar: number;
    .
    .
    .
  }
  </code></pre>
  
  <p>This is possible using index signature on <code>Data</code> with a non-variable string.</p>
  
  <pre class="lang-js prettyprint-override"><code>type propType = Data['foo']; // propType = 'string'
  </code></pre>
  
  <p>However, it does <strong>not</strong> work using a variable.</p>
  
  <pre class="lang-js prettyprint-override"><code>const propName = 'foo';
  type propType = Data[propName]; // Errors
  </code></pre>
  
  <p>Errors:</p>
  
  <ul>
  <li>Type 'any' cannot be used as an index type.ts(2538)</li>
  <li>'propName' refers to a value, but is being used as a type here.ts(2749)</li>
  </ul>
  
  <p>Neither of these errors make sense, because <code>propName</code> is definitely a <code>string</code> not <code>any</code>, and it is not "being used as a type here." </p>
  
  <p><strong>Update</strong></p>
  
  <p>As it might be obvious, I was trying to do something impossible. After much fighting, I've finally accepted that uninstantiated interfaces do not and will not ever have property or property-type information at run-time.</p>
  
  <p>This method using <code>type</code> will work, but only at compile-time. I approved the answer with the correct syntax.</p>
  
  <p>(Still think the error messages in my question are weird though.)</p>