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.

16 lines
335 B

2 years ago
  1. // 泛型工具类型:Readonly<Type> 将 Type 的所有属性都设置为 readonly(只读)
  2. interface Props {
  3. id: string
  4. children: number[]
  5. }
  6. type ReadonlyProps = Readonly<Props>
  7. // 所有属性都是只读
  8. let p1: ReadonlyProps = {
  9. id: '1',
  10. children: [1, 3]
  11. }
  12. // 属性是只读,不能修改
  13. // p1.id = '2'