Created
August 28, 2013 05:16
-
-
Save staxmanade/6362371 to your computer and use it in GitHub Desktop.
Goofing around with TypeScript, interfaces, inheritance, generics etc...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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