Closed1
【TypeScript】typeof

- TypeScriptのtypeofは変数の型を抽出する
- 型を再利用したい時に使える
- JavaScriptのtypeofは値の型を調べるために使う(TypeScriptのtypofとは別物)
const person = {
name: 'Taro',
age: 20,
}
type Person = typeof person;
const greet = (person: Person) => {
console.log(`Hello, ${person.name}`);
}
greet(person); // Hello, Taro
このスクラップは6ヶ月前にクローズされました