作者:xie392地址:https://v.douyin.com/ieQtm3cC/更新时间:2024-12-21
1type DeepReadonly<T extends Record<string|symbol, any>> = {2readonly [K in keyof T]: DeepReadonly<T[K]> // 深度克隆3}45interface Person {6name: string7age: number8obj: {9a: number10}11}1213const person: DeepReadonly<Person> = {14name: 'xie',15age: 18,16obj: {17a: 118}19}2021// person.obj.a = 2 // error: 无法为“a”赋值,因为它是只读属性。