title: Typescript static class generic functions
body: <p>Trying to understand typescript generics + static class functions a bit more thoroughly, and I am running into to some type problems:</p>
  
  <pre><code>class Base {
    value : string = 'default'
  
    static identity&lt;M extends typeof Base&gt;() : M  {
      return this // Type Error: Type 'typeof Base' is not assignable to type 'M'
    }
  }
  
  class Extended extends Base {
    otherValue = 'extended'
  
    constructor() {
      super()
    }
  }
  
  let baseClass = Base.identity()
  let extendedClass = Extended.identity()
  expect(new baseClass().value).to.eq('default')
  
  // Type Error: Property 'otherValue' does not exist on type 'Base'
  // How do I make Extended.identity() be `typeof Extended` without
  // an explicit cast?
  expect(new extendedClass().otherValue).to.eq('extended')
  </code></pre>
  
  <p>If I ignore type errors and run the output code, everything runs as expected and expectations are met. I think this is probably due to some understanding gaps with static functions, but any help in understanding the problem would be much appreciated.</p>