title: Using a generic type argument with `typeof T`
body: <p>I have a factory-like function that is meant to return an sub-class instance of <code>BaseApi</code>. It currently looks something like this (trimmed out irrelevant parts):</p>
  
  <pre><code>function getApi&lt;T extends BaseApi&gt;(apiClass: typeof BaseApi): T {
      return new apiClass();
  }
  </code></pre>
  
  <p>And I use it like this:</p>
  
  <pre><code>const someApi = getApi&lt;SomeApi&gt;(SomeApi);
  </code></pre>
  
  <p>This works, but I would like <code>&lt;SomeApi&gt;</code> to be inferred by virtue of the fact that I'm passing the <code>SomeApi</code> constructor in. If I omit <code>&lt;SomeApi&gt;</code> then <code>someApi</code> is inferred to be of type <code>BaseApi</code>, not <code>SomeApi</code>. Worse, there's really no compiler correlation between <code>&lt;T extends BaseApi&gt;</code> and <code>typeof BaseApi</code> being the same thing, so you can incorrectly do something like <code>getApi&lt;SecondApi&gt;(FirstApi)</code> without a compiler error.</p>
  
  <p>So I tried defining the <code>apiClass</code> as <code>typeof T</code>:</p>
  
  <pre><code>function getApi&lt;T extends BaseApi&gt;(apiClass: typeof T): T {
      return new apiClass();
  }
  </code></pre>
  
  <p>And I found that TS did not understand this usage of <code>T</code>. Is there any way to do this?</p>