Record<Keys,Type>
构造一个对象类型,其属性key是Keys
,属性value是Tpye
。被用于映射一个类型的属性到另一个类型
interface 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'}
};
cats.boris;