18. 对象属性深度只读

中等0

创建一个通用的工具类型 DeepReadonly<T> ,它将对象的每个参数及其子对象递归地设为只读。

您可以假设在此挑战中我们仅处理对象,不考虑数组、函数、类等。

例如:

type X = { 
  x: { 
    a: 1
    b: 'hi'
  }
  y: 'hey'
}

type Expected = { 
  readonly x: { 
    readonly a: 1
    readonly b: 'hi'
  }
  readonly y: 'hey' 
}

type DeepReadonlyX = DeepReadonly<X> // should be same as `Expected`
评论(0)
题库

TypeScript

加载中...