keyof T
interface / type aliasesで定義されたオブジェクト型 Tのプロパティ名の共用体型(union type)を返します。
type User = { name : string, age : number, occupation: string }; type KeyTypes = keyof User; // type KeyTypes = "name" | "age" | "occupation"
keyof typeof Object
オブジェクト(Object)のプロパティ名の共用体型(union type)を返します。
const user = { name: 'Anthony', age: 32, occupation: 'engineer' }; type KeyTypes = keyof typeof user; // type KeyTypes = "name" | "age" | "occupation"