2021-08-01から1ヶ月間の記事一覧
// 継承にのみ利用できるクラスにはabstractを利用 abstract class Person { // インスタンス作らずにクラスを使う場合はstaticを利用する // 例 Person.species static species = 'Homo sapiens'; // インスタンス作らずにクラスを使う場合はstaticを利用す…
// オブジェクトのキーのunion型を作る // U extends keyof Tのようにすると、Uの型は、name | ageのunion型になります。 function copy<T extends { name: string }, U extends keyof T>(value: T, key: U): T { value[key]; return value; } console.log(copy({ name: 'Quill', age: 20}, 'age')); // clas</t>…
// ------------- インターセクション ------------- // エンジニアの型を定義 interface Engineer { name: string; role: string; } // ブロガーの型を定義 interface Blogger { name: string; follower: number; } // type EngineerBlogger = Engineer & B…