ts之Record类型:
Record是TypeScript中的一个实用工具类型。它用于创建一个对象类型,其属性键为K类型,属性值为T类型。Record的基本语法如下:
语法:
Record<K, T>
使用:
type Product = {
name: string;
price: number;
};
const products: Record<string, Product> = {
apple: { name: 'Apple', price: 0.5 },
banana: { name: 'Banana', price: 0.25 },
};
console.log(products.apple); // { name: 'Apple', price: 0.5 }
参考:
https://gibbok.github.io/typescript-book/zh-cn/book/type-manipulation/ //类型操作
https://gibbok.github.io/typescript-book/zh-cn/book/generics/
https://sourcegraph.com/github.com/wangdoc/typescript-tutorial/-/blob/docs/utility.md //很多md文档语法可以参考
