You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
400 B

2 years ago
  1. // 泛型工具类型:Record<Keys, type> 构造一个对象类型,属性键为 Keys, 属性类型为 Type
  2. type RecordObj = Record< 'a' | 'b' | 'c', string[]> // 表示属性键 a、b、c 都是 string 类型的数组
  3. let obj: RecordObj = {
  4. a: ['a'],
  5. b: ['b'],
  6. c: ['c']
  7. }
  8. // 不使用工具类型 Record
  9. type RecordObj2 = {
  10. a2: string[]
  11. b2: string[]
  12. c2: string[]
  13. }