Issue 1:
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.

abstract class Foo {
public static construct(...args:any[]):Foo {
return new (<any>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 }

In Bar I want to define the same constructor signature for the static construct method. I've tried several things without much success:

Interfaces are not an option, explained clearly in #1263.

Could potentially have an intermediary abstract class with all declarations, but static cannot be abstract. Reasonable.

Definition merging sounded promising, but class merging is not allowed. Yet?

Override the actual method with an actual implementation – this is not really an answer, it results in too much code that does absolutely nothing.

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.

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;
}
}

This fails to compile with Duplicate identifier 'Baz' 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:

Ambient declarations don't do much besides type checking and hinting.

Can be injected into final declarations produced by compiler.

Final declarations are fully reusable.

Issue 2:
When trying to implement a fairly basic, but polymorphic, active record style model system we run into issues with the type system not respecting this when used in conjunction with a constructor or template/generic.

I've posted before about this here, #5493, and #5492 appears to mention this behavior also.

And here is an SO post this that I made:

http://stackoverflow.com/questions/33443793/create-a-generic-factory-in-typescript-unsolved

I have recycled my example from #5493 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.

Here is an example that outlines a model Factory which produces models. If you want to customize the BaseModel that comes back from the Factory you should be able to override it. However this fails because this cannot be used in a static member.

// Typically in a library
export interface InstanceConstructor<T extends BaseModel> {
new(fac: Factory<T>): T;
}

export class Factory<T extends BaseModel> {
constructor(private cls: InstanceConstructor<T>) {}

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

export class BaseModel {
// NOTE: Does not work....
constructor(private fac: Factory<this>) {}

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 "Model" type
let f = new Factory<Model>(Model);
let a = f.get();

// b is inferred as any here.
let b = a.refresh();

Maybe this issue is silly and there is an easy workaround. I welcome comments regarding how such a pattern can be achieved.