Last active
May 20, 2019 20:28
-
-
Save JimRottinger/afe747181b0003343d8c99b2cbaa4539 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 GenericInterface<U> { | |
value: U | |
getIdentity: () => U | |
} | |
class IdentityClass<T> implements GenericInterface<T> { | |
value: T | |
constructor(value: T) { | |
this.value = value | |
} | |
getIdentity () : T { | |
return this.value | |
} | |
} | |
const myNumberClass = new IdentityClass<Number>(1) | |
console.log(myNumberClass.getIdentity()) // 1 | |
const myStringClass = new IdentityClass<string>("Hello!") | |
console.log(myStringClass.getIdentity()) // Hello! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment