<p dir="auto">When I am writing a declaration file, I found it really frustrating repeating the inherited method that returns the instance itself for a correct return type.</p>
<p dir="auto">E.g. for animation library GSAP, many classes are inherited from class <code class="notranslate">Animation</code>, I have to repeat almost every method to update return type <code class="notranslate">Animation</code> to the current class.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Animation {
    chain(): Animation;
}

class TweenLite extends Animation {
    ownProperty: any;
    chain(): TweenLite;
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Animation</span> <span class="pl-kos">{</span>
    <span class="pl-c1">chain</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">Animation</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">TweenLite</span> <span class="pl-k">extends</span> <span class="pl-smi">Animation</span> <span class="pl-kos">{</span>
    <span class="pl-c1">ownProperty</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>
    <span class="pl-c1">chain</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">TweenLite</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">It would be great if we may use some type like <code class="notranslate">self</code> to make this easier, like this:</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Animation {
    chain(): self;
}

class TweenLite extends Animation {
    ownProperty: any;
}"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-smi">Animation</span> <span class="pl-kos">{</span>
    <span class="pl-c1">chain</span><span class="pl-kos">(</span><span class="pl-kos">)</span>: <span class="pl-smi">self</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">TweenLite</span> <span class="pl-k">extends</span> <span class="pl-smi">Animation</span> <span class="pl-kos">{</span>
    <span class="pl-c1">ownProperty</span>: <span class="pl-smi">any</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">The early discussions about generics had this feature outlined, but it never made it into the final version for some reason. Meanwhile, it would be extremely helpful in some cases. The use case that it most dear to my heart is Knockout:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="interface Observable&lt;T&gt; {
   &lt;U&gt;( this: U, value: T ): U;
}

var viewModel = {
   Str: ko.observable( &quot;abc&quot; ),
   Num: ko.observable( 5 )
};

viewModel.Str( &quot;xyz&quot; ).Num( 10 );"><pre class="notranslate"><code class="notranslate">interface Observable&lt;T&gt; {
   &lt;U&gt;( this: U, value: T ): U;
}

var viewModel = {
   Str: ko.observable( "abc" ),
   Num: ko.observable( 5 )
};

viewModel.Str( "xyz" ).Num( 10 );
</code></pre></div>