[typescript] 타입 문법 keyof typeof


[typescript] 타입 문법 keyof typeof

keyof 연산자 객체 타입에서 프로퍼티 이름들을 모아서 Union한 타입으로 만들고 싶을 때 사용합니다. interface Product { id: string; name: string; price: number; membersOnly?: boolean; } type ProductProperty = keyof Product; // 'id' | 'name' | 'price' | 'membersOnly'; typeof 연산자 자바스크립트 코드에서 사용하면 결괏값이 문자열이지만, 타입스크립트 코드에서 쓸 때는 결과 값은 타입스크립트의 타입입니다. const product: Product = { id: 'c001', name: '블랙 후드 집업', price: 129000, salePrice: 98000, m..


원문링크 : [typescript] 타입 문법 keyof typeof