type을 서로 엮어서 만들 수 있다.
Record<Keys, Type>
Keys가 Record로 반환되는 타입의 키가 되고
Type은 각 Keys의 타입
/**
* Construct a type with a set of properties K of type T
*/
type Record<K extends keyof any, T> = {
[P in K]: T;
};
// e.g.,
type CatInfo = {
age: number;
breed: string;
}
type CatName = "miffy" | "boris" | "mordred";
const cats: Record<CatName, CatInfo> = {
miffy: { age: 10, breed: "Persian" },
boris: { age: 5, breed: "Maine Coon" },
mordred: { age: 16, breed: "British Shorthair" },
};
console.log(cats.boris.age); // 5