Skip to content

Instantly share code, notes, and snippets.

@JimRottinger
Last active May 20, 2019 20:28
Show Gist options
  • Save JimRottinger/afe747181b0003343d8c99b2cbaa4539 to your computer and use it in GitHub Desktop.
Save JimRottinger/afe747181b0003343d8c99b2cbaa4539 to your computer and use it in GitHub Desktop.
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