<p dir="auto">Need to allow to use generics for "this" type, like this: <code class="notranslate">this&lt;T&gt;</code></p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Collection&lt;T&gt; extends Array&lt;T&gt; {

    map&lt;U&gt;(callbackfn: (value: T, index: number, array: T[]) =&gt; U, thisArg?: any): this { 
        // this method will return this&lt;T&gt;, but I want to return this&lt;U&gt;
        return new (this.constructor as any)(...super.map(callbackfn, thisArg));
    }

}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Collection</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-k">extends</span> <span class="pl-smi">Array</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>

    <span class="pl-en">map</span><span class="pl-c1">&lt;</span><span class="pl-smi">U</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">callbackfn</span>: <span class="pl-kos">(</span><span class="pl-s1">value</span>: <span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-s1">index</span>: <span class="pl-smi">number</span><span class="pl-kos">,</span> <span class="pl-s1">array</span>: <span class="pl-smi">T</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">U</span><span class="pl-kos">,</span> <span class="pl-s1">thisArg</span>?: <span class="pl-smi">any</span><span class="pl-kos">)</span>: this <span class="pl-kos">{</span> 
        <span class="pl-c">// this method will return this&lt;T&gt;, but I want to return this&lt;U&gt;</span>
        <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span> <span class="pl-k">as</span> <span class="pl-smi">any</span><span class="pl-kos">)</span><span class="pl-kos">(</span>...<span class="pl-smi">super</span><span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">callbackfn</span><span class="pl-kos">,</span> <span class="pl-s1">thisArg</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>

<span class="pl-kos">}</span></pre></div>
<p dir="auto">example of usage:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="new Collection(
    new Model(1, &quot;Mercedes&quot;),
    new Model(2, &quot;BMW&quot;),
    new Model(3, &quot;Ford&quot;)
)
    .map(model =&gt; model.engine)
    .forEach(engine =&gt; engine.serialNumber); // here compiler should see engine.serialNumber"><pre class="notranslate"><span class="pl-k">new</span> <span class="pl-smi">Collection</span><span class="pl-kos">(</span>
    <span class="pl-k">new</span> <span class="pl-smi">Model</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">,</span> <span class="pl-s">"Mercedes"</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-k">new</span> <span class="pl-smi">Model</span><span class="pl-kos">(</span><span class="pl-c1">2</span><span class="pl-kos">,</span> <span class="pl-s">"BMW"</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-k">new</span> <span class="pl-smi">Model</span><span class="pl-kos">(</span><span class="pl-c1">3</span><span class="pl-kos">,</span> <span class="pl-s">"Ford"</span><span class="pl-kos">)</span>
<span class="pl-kos">)</span>
    <span class="pl-kos">.</span><span class="pl-en">map</span><span class="pl-kos">(</span><span class="pl-s1">model</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">model</span><span class="pl-kos">.</span><span class="pl-c1">engine</span><span class="pl-kos">)</span>
    <span class="pl-kos">.</span><span class="pl-en">forEach</span><span class="pl-kos">(</span><span class="pl-s1">engine</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">engine</span><span class="pl-kos">.</span><span class="pl-c1">serialNumber</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// here compiler should see engine.serialNumber</span></pre></div>
<p dir="auto">First, thank you team for polymorphic <code class="notranslate">this</code>.  It is really handy!</p>
<p dir="auto">I think I ran into a case though that I am finding challenging, when I need to return a <code class="notranslate">this</code>, but the generics might have changed.  For example:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A&lt;T&gt; {
    private items: T[] = [];
    map&lt;U&gt;(callback: (item: T, idx: number, a: this) =&gt; U): this {
        // boring implementation details
    });
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">A</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">private</span> <span class="pl-c1">items</span>: <span class="pl-smi">T</span><span class="pl-kos">[</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-en">map</span><span class="pl-c1">&lt;</span><span class="pl-smi">U</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">callback</span>: <span class="pl-kos">(</span><span class="pl-s1">item</span>: <span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-s1">idx</span>: <span class="pl-smi">number</span><span class="pl-kos">,</span> <span class="pl-s1">a</span>: this<span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">U</span><span class="pl-kos">)</span>: this <span class="pl-kos">{</span>
        <span class="pl-c">// boring implementation details</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Where I want to be able to change the generic type for the class with a function, but I will be contracting to return the "current" class, but I want to guard different generics.  The following seems logical to me, but doesn't appear to be currently supported:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class A&lt;T&gt; {
    private items: T[] = [];
    map&lt;U&gt;(callback: (item: T, idx: number, a: this) =&gt; U): this&lt;U&gt; {
        // boring implementation details
    });
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">A</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">private</span> <span class="pl-c1">items</span>: <span class="pl-smi">T</span><span class="pl-kos">[</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-c1">map</span><span class="pl-c1">&lt;</span><span class="pl-smi">U</span><span class="pl-c1">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">callback</span>: <span class="pl-kos">(</span><span class="pl-s1">item</span>: <span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-s1">idx</span>: <span class="pl-smi">number</span><span class="pl-kos">,</span> <span class="pl-s1">a</span>: this<span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-smi">U</span><span class="pl-kos">)</span>: <span class="pl-smi">this</span><span class="pl-c1">&lt;</span><span class="pl-smi">U</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-c">// boring implementation details</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">Where if no generics arguments are supplied, it is inferred to be the current ones, where as if they are supplied they are substituted.</p>