title: Implementing fluent generic class methods Typescript
body: <p>How does one implement a fluent (chainable) generic map function on a collection class? Consider the below:</p>
  
  <pre class="lang-js prettyprint-override"><code>class Array_&lt;T&gt; {
      private _arr: T[]
  
      constructor(iterable: Iterable&lt;T&gt;) { this._arr = [...iterable] }
  
      [Symbol.iterator]() { return this._arr[Symbol.iterator]() }
  
      map&lt;Y&gt;(projector: (item: T) =&gt; Y): Array_&lt;Y&gt; {
          return new Array_((function* (iterable: Iterable&lt;T&gt;) {
              for (const element of iterable) {
                  yield projector(element)
              }
          })(this))
      }
  }
  
  class ArrayCustom&lt;T&gt; extends Array&lt;T&gt; { }
  
  let mappedArr = new ArrayCustom([1,2,3]).map(element=&gt;element.toString())
  </code></pre>
  
  <p>The inferred type of <code>mappedArr</code> is <code>Array_&lt;string&gt;</code>, but I want it to be <code>ArrayCustom&lt;string&gt;</code></p>