Skip to content

Instantly share code, notes, and snippets.

@tfrcm
Last active April 22, 2019 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfrcm/9972f51dc2f4b5c3452399921f324825 to your computer and use it in GitHub Desktop.
Save tfrcm/9972f51dc2f4b5c3452399921f324825 to your computer and use it in GitHub Desktop.
TypeScript1.8 入門④ (ジェネリクス) ref: https://qiita.com/tfrcm/items/cd8dafcc8ee4f824ccf5
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