Last active
April 22, 2019 13:41
-
-
Save tfrcm/9972f51dc2f4b5c3452399921f324825 to your computer and use it in GitHub Desktop.
TypeScript1.8 入門④ (ジェネリクス) ref: https://qiita.com/tfrcm/items/cd8dafcc8ee4f824ccf5
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 Result { | |
a: number; | |
b: number; | |
} | |
class MyData<T extends Result> { | |
constructor(public value: T) {} | |
getArray(): T[] { | |
return [this.value, this.value, this.value]; | |
} | |
} | |
let result = { | |
a: 3, | |
b: 5 | |
}; | |
let v1 = new MyData<Result>(result); | |
console.log(v1.getArray()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment