title: TypeScript: self-referencing return type for static methods in inheriting classes
body: <p>With <a href="https://github.com/Microsoft/TypeScript/pull/4910" rel="noreferrer">Polymorphic this</a> in TypeScript 1.7, as I discovered <a href="https://stackoverflow.com/questions/34095437/typescript-self-referencing-return-type-for-methods-in-inheriting-classes">here</a>, we can define a method in a class with a return type of <code>this</code>, and automatically, any classes that extend that class and inherit the methods, will have their return types set to their respective <code>this</code> type. Like so:</p>
  
  <pre><code>class Model {
    save():this {    // return type: Model
      // save the current instance and return it
    }
  }
  
  class SomeModel extends Model {
    // inherits the save() method - return type: SomeModel
  }
  </code></pre>
  
  <p>However, what I'm after is to have an inherited <code>static</code> method with a return type referencing the class itself. It's best described in code:</p>
  
  <pre><code>class Model {
    static getAll():Model[] {
      // return all recorded instances of Model as an array
    }
  
    save():this {
      // save the current instance and return it
    }
  }
  
  class SomeModel extends Model {
    // inherits the save() method - return type: SomeModel
    // also inherits getAll() - return type: Model (how can we make that SomeModel?)
  }
  </code></pre>
  
  <p>Perhaps I'll have to think of a different way to implement this, since Polymorphic <code>this</code> in TypeScript 1.7 does not support <code>static</code> methods <em>by design</em>.</p>
  
  <p><strong>EDIT</strong>: I guess we'll see how this Github issue wraps up: <a href="https://github.com/Microsoft/TypeScript/issues/5863" rel="noreferrer">https://github.com/Microsoft/TypeScript/issues/5863</a></p>