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.

17 lines
418 B

2 years ago
  1. // 泛型工具类型:Partial<Type> 用来构造(创建)一个类型,将 Type 的所有属性设置为可选
  2. interface Props {
  3. id: string
  4. children: number[]
  5. }
  6. // 使用 泛型工具 Partial
  7. type PartialProps = Partial<Props>
  8. // 没有用泛型工具,属性是必加的
  9. let p1: Props = {
  10. id: '',
  11. children: [1]
  12. }
  13. // 加入 PartialProps 后,属性可加可不加
  14. let p2: PartialProps = {}