<p dir="auto">I searched issues and SO, this seems to be something that comes up often, but there's no definitive / any answer to this. I have a proposal.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="abstract class Foo {
    public static construct(...args:any[]):Foo {
        return new (&lt;any&gt;this)(...args);
    }
}

class Bar extends Foo {
    protected x:any;
    public constructor(x?:any) {
        super();
        this.x = x;
    }
}

console.log(Bar.construct(1)); // Bar { x: 1 }"><pre class="notranslate"><span class="pl-k">abstract</span> <span class="pl-k">class</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-en">construct</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span>:<span class="pl-smi">any</span><span class="pl-kos">[</span><span class="pl-kos">]</span><span class="pl-kos">)</span>:<span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-kos">(</span><span class="pl-kos">&lt;</span><span class="pl-smi">any</span><span class="pl-kos">&gt;</span><span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">(</span>...<span class="pl-s1">args</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Bar</span> <span class="pl-k">extends</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">protected</span> <span class="pl-c1">x</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
    <span class="pl-k">public</span> <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-s1">x</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-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-smi">Bar</span><span class="pl-kos">.</span><span class="pl-en">construct</span><span class="pl-kos">(</span><span class="pl-c1">1</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span> <span class="pl-c">// Bar { x: 1 }</span></pre></div>
<p dir="auto">In <code class="notranslate">Bar</code> I want to define the same constructor signature for the static <code class="notranslate">construct</code> method. I've tried several things without much success:</p>
<ul dir="auto">
<li>Interfaces are not an option, explained clearly in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="49983101" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/1263" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/1263/hovercard" href="https://github.com/microsoft/TypeScript/issues/1263">#1263</a>.</li>
<li>Could potentially have an intermediary abstract class with all declarations, but static cannot be abstract. Reasonable.</li>
<li>Definition merging sounded promising, but class merging is not allowed. Yet?</li>
<li>Override the actual method with an actual implementation – this is not really an answer, it results in too much code that does absolutely nothing.</li>
</ul>
<p dir="auto">There's one solution that partially works. Partially, because it gives JetBrains IDE the necessary hinting, that's all I want for now. Besides that it's useless.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="declare class Baz extends Foo {
    public static instance(y?:any):Baz;
}

class Baz extends Foo {
    protected y:any;
    public constructor(y?:any) {
        super();
        this.y = y;
    }
}"><pre class="notranslate"><span class="pl-k">declare</span> <span class="pl-k">class</span> <span class="pl-smi">Baz</span> <span class="pl-k">extends</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-c1">instance</span><span class="pl-kos">(</span><span class="pl-s1">y</span>?:<span class="pl-smi">any</span><span class="pl-kos">)</span>:<span class="pl-smi">Baz</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">class</span> <span class="pl-smi">Baz</span> <span class="pl-k">extends</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">protected</span> <span class="pl-c1">y</span>:<span class="pl-smi">any</span><span class="pl-kos">;</span>
    <span class="pl-k">public</span> <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-s1">y</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-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">y</span> <span class="pl-c1">=</span> <span class="pl-s1">y</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">This fails to compile with <code class="notranslate">Duplicate identifier 'Baz'</code> error. If the ambient declaration moved somewhere else, so that typescript doesn't compile it, then the IDE gets the hinting and tsc doesn't fail. But couldn't that just work like in example above? The rationale is:</p>
<ul dir="auto">
<li>Ambient declarations don't do much besides type checking and hinting.</li>
<li>Can be injected into final declarations produced by compiler.</li>
<li>Final declarations are fully reusable.</li>
</ul>
<p dir="auto">When trying to implement a fairly basic, but polymorphic, active record style model system we run into issues with the type system not respecting <code class="notranslate">this</code> when used in conjunction with a constructor or template/generic.</p>
<p dir="auto">I've posted before about this here, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="114630380" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/5493" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5493/hovercard" href="https://github.com/microsoft/TypeScript/issues/5493">#5493</a>, and <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="114586216" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/5492" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5492/hovercard" href="https://github.com/microsoft/TypeScript/issues/5492">#5492</a> appears to mention this behavior also.</p>
<p dir="auto">And here is an SO post this that I made:<br>
<a href="http://stackoverflow.com/questions/33443793/create-a-generic-factory-in-typescript-unsolved" rel="nofollow">http://stackoverflow.com/questions/33443793/create-a-generic-factory-in-typescript-unsolved</a></p>
<p dir="auto">I have recycled my example from <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="114630380" data-permission-text="Title is private" data-url="https://github.com/microsoft/TypeScript/issues/5493" data-hovercard-type="issue" data-hovercard-url="/microsoft/TypeScript/issues/5493/hovercard" href="https://github.com/microsoft/TypeScript/issues/5493">#5493</a> into this ticket for further discussion. I wanted an open ticket representing the desire for such a thing and for discussion but the other two are closed.</p>
<p dir="auto">Here is an example that outlines a model <code class="notranslate">Factory</code> which produces models. If you want to customize the <code class="notranslate">BaseModel</code> that comes back from the <code class="notranslate">Factory</code> you should be able to override it. However this fails because <code class="notranslate">this</code> cannot be used in a static member.</p>
<div class="highlight highlight-source-ts notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="// Typically in a library
export interface InstanceConstructor&lt;T extends BaseModel&gt; {
    new(fac: Factory&lt;T&gt;): T;
}

export class Factory&lt;T extends BaseModel&gt; {
    constructor(private cls: InstanceConstructor&lt;T&gt;) {}

    get() {
        return new this.cls(this);
    }
}

export class BaseModel {
    // NOTE: Does not work....
    constructor(private fac: Factory&lt;this&gt;) {}

    refresh() {
        // get returns a new instance, but it should be of
        // type Model, not BaseModel.
        return this.fac.get();
    }
}

// Application Code
export class Model extends BaseModel {
    do() {
        return true;
    }
}

// Kinda sucks that Factory cannot infer the &quot;Model&quot; type
let f = new Factory&lt;Model&gt;(Model);
let a = f.get();

// b is inferred as any here.
let b = a.refresh();"><pre class="notranslate"><span class="pl-c">// Typically in a library</span>
<span class="pl-k">export</span> <span class="pl-k">interface</span> <span class="pl-smi">InstanceConstructor</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span> <span class="pl-k">extends</span> <span class="pl-smi">BaseModel</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">new</span><span class="pl-kos">(</span><span class="pl-s1">fac</span>: <span class="pl-smi">Factory</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-smi">T</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Factory</span><span class="pl-c1">&lt;</span><span class="pl-smi">T</span> <span class="pl-k">extends</span> <span class="pl-smi">BaseModel</span><span class="pl-c1">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-k">private</span> <span class="pl-s1">cls</span>: <span class="pl-smi">InstanceConstructor</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-kos">{</span><span class="pl-kos">}</span>

    <span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">cls</span><span class="pl-kos">(</span><span class="pl-smi">this</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">BaseModel</span> <span class="pl-kos">{</span>
    <span class="pl-c">// NOTE: Does not work....</span>
    <span class="pl-en">constructor</span><span class="pl-kos">(</span><span class="pl-k">private</span> <span class="pl-s1">fac</span>: <span class="pl-smi">Factory</span><span class="pl-kos">&lt;</span>this<span class="pl-kos">&gt;</span><span class="pl-kos">)</span> <span class="pl-kos">{</span><span class="pl-kos">}</span>

    <span class="pl-en">refresh</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-c">// get returns a new instance, but it should be of</span>
        <span class="pl-c">// type Model, not BaseModel.</span>
        <span class="pl-k">return</span> <span class="pl-smi">this</span><span class="pl-kos">.</span><span class="pl-c1">fac</span><span class="pl-kos">.</span><span class="pl-en">get</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>

<span class="pl-c">// Application Code</span>
<span class="pl-k">export</span> <span class="pl-k">class</span> <span class="pl-smi">Model</span> <span class="pl-k">extends</span> <span class="pl-smi">BaseModel</span> <span class="pl-kos">{</span>
    <span class="pl-en">do</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-k">return</span> <span class="pl-c1">true</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>

<span class="pl-c">// Kinda sucks that Factory cannot infer the "Model" type</span>
<span class="pl-k">let</span> <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-k">new</span> <span class="pl-smi">Factory</span><span class="pl-kos">&lt;</span><span class="pl-smi">Model</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-smi">Model</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">let</span> <span class="pl-s1">a</span> <span class="pl-c1">=</span> <span class="pl-s1">f</span><span class="pl-kos">.</span><span class="pl-en">get</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// b is inferred as any here.</span>
<span class="pl-k">let</span> <span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span><span class="pl-kos">.</span><span class="pl-en">refresh</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<p dir="auto">Maybe this issue is silly and there is an easy workaround. I welcome comments regarding how such a pattern can be achieved.</p>