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
335 B
17 lines
335 B
// 泛型工具类型:Readonly<Type> 将 Type 的所有属性都设置为 readonly(只读)
|
|
|
|
interface Props {
|
|
id: string
|
|
children: number[]
|
|
}
|
|
|
|
type ReadonlyProps = Readonly<Props>
|
|
|
|
// 所有属性都是只读
|
|
let p1: ReadonlyProps = {
|
|
id: '1',
|
|
children: [1, 3]
|
|
}
|
|
|
|
// 属性是只读,不能修改
|
|
// p1.id = '2'
|