Utility Type - 5
→ property key를 K, K의 타입을 T로 구성한 세트 유형 생성
/**
* *Construct a type with a set of properties K of type T*
*/
type Record<K extends keyof any, T> = {
[P in K]: T;
};
type PageInfo = { *// Value(Type)*
title: string;
local: number;
};
type Page = 'home' | 'about' | 'contact'; *// Key(property)*
const nav: Record<Page, PageInfo> = {
home: { title: 'Home1', local: 1 },
about: { title: 'About2', local: 2 },
contact: { title: 'contact3', local: 3 },
}
console.log(nav);
Record<K extends keyof any, T> 로 예제에서 Page 를 키(key)로 두고, PageInfo 를 값(value)으로 로 두는 방법이다.