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.

20 lines
545 B

2 years ago
  1. type Props = { a: number; b: string; c: boolean }
  2. // 查看 Props 中 a 的类型
  3. type TypeA = Props['a']
  4. // 模拟 Partial 类型:
  5. type MyPartial<T> = {
  6. [P in keyof T]?: T[P] // p 相当于 key
  7. }
  8. type PartialProps = MyPartial<Props>
  9. // 索引其它查询方式:同时查询多个索引的类型
  10. type TypeB = Props['a' | 'b']
  11. type Props2 = { a: number; b: number; c: boolean }
  12. type TypeC = Props2['a' | 'b']
  13. // a 和 b 类型都是 number,TypeD 只显示一个 number,实现去重功能
  14. type TypeD = Props2[keyof Props]