Skip to content

Instantly share code, notes, and snippets.

@russleyshaw
Last active September 15, 2017 21:49
Show Gist options
  • Save russleyshaw/f287be9b260d93649cd7ede5077839da to your computer and use it in GitHub Desktop.
Save russleyshaw/f287be9b260d93649cd7ede5077839da to your computer and use it in GitHub Desktop.
Allow generic extended construction.
interface FooConstructor<T> {
new(val: number): T;
}
interface FooInterface {
myVal: number;
}
class Foo implements FooInterface {
myVal: number;
constructor(val: number) {
this.myVal = val;
}
doFoo() { }
}
class Bar<T extends FooInterface> {
public doot: T;
constructor(ctor: FooConstructor<T>) {
this.doot = new ctor(4);
}
}
const f = new Bar(Foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment