Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Created August 28, 2013 05:16
Show Gist options
  • Save staxmanade/6362371 to your computer and use it in GitHub Desktop.
Save staxmanade/6362371 to your computer and use it in GitHub Desktop.
Goofing around with TypeScript, interfaces, inheritance, generics etc...
interface IAmSomeInterface {
getNumber(): number;
}
interface IAmAGenericInterface<T extends IAmSomeInterface> {
getInstanceOfSomeInterface(id: number): T;
}
class ClassExtendingSomeInterface implements IAmSomeInterface {
getNumber() {
return 1;
}
}
class Test implements IAmAGenericInterface<ClassExtendingSomeInterface> {
public getInstanceOfSomeInterface(id: number) {
//return new ClassExtendingSomeInterface();
return (function () {
return {
getNumber: function () { return 2; }
};
})();
}
}
class Test2 extends Test {
public getInstanceOfSomeInterface(id: number) {
return super.getInstanceOfSomeInterface(id);
}
}
var x = new Test();
var x2 = new Test2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment