title: TypeScript polymorphic return type
body: <p>Let's say we want to implement data types hierarchy, what type should be used?</p>
  
  <pre><code>interface Collection&lt;T&gt; {
    map(f: (v: T) =&gt; T): ???
  }
  
  interface Array&lt;T&gt; extends Collection&lt;T&gt; {
    map(f: (v: T) =&gt; T): ??? { return new Array&lt;T&gt;() }
  }
  
  interface LinkedList&lt;T&gt; extends Collection&lt;T&gt; {
    map(f: (v: T) =&gt; T): ??? { return new LinkedList&lt;T&gt;() }
  }
  </code></pre>
  
  <p>Polymorhping <code>this</code> is not working</p>
  
  <pre><code>interface Collection&lt;T&gt; {
    map(f: (v: T) =&gt; T): this
  }
  
  interface Array&lt;T&gt; extends Collection&lt;T&gt; {
    map(f: (v: T) =&gt; T): this { return new Array&lt;T&gt; }
    // ^ error `Error: type Array&lt;T&gt; is not assignable to type this`
  }
  </code></pre>