Back to Type Challenges

README.Zh CN

questions/17973-medium-deepmutable/README.zh-CN.md

latest2.1 KB
Original Source
<!--info-header-start--><h1>DeepMutable </h1><blockquote><p>by cutefcc <a href="https://github.com/cutefcc" target="_blank">@cutefcc</a></p></blockquote><p><a href="https://tsch.js.org/17973/play/zh-CN" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.md" target="_blank"></a> </p><!--info-header-end-->

实现一个通用的 DeepMutable<T> ,它使对象的每个属性,及其递归的子属性 - 可变。

例如:

ts
type X = {
  readonly a: () => 1
  readonly b: string
  readonly c: {
    readonly d: boolean
    readonly e: {
      readonly g: {
        readonly h: {
          readonly i: true
          readonly j: "s"
        }
        readonly k: "hello"
      }
    }
  }
}

type Expected = {
  a: () => 1
  b: string
  c: {
    d: boolean
    e: {
      g: {
        h: {
          i: true
          j: "s"
        }
        k: "hello"
      }
    }
  }
}

type Todo = DeepMutable<X> // should be same as `Expected`

你可以假设我们在这个挑战中只处理对象。 数组、函数、类等不需要考虑。 但是,您仍然可以通过涵盖尽可能多的不同案例来挑战自己。

<!--info-footer-start-->

<a href="../../README.zh-CN.md" target="_blank"></a> <a href="https://tsch.js.org/17973/answer/zh-CN" target="_blank"></a> <a href="https://tsch.js.org/17973/solutions" target="_blank"></a> <!--info-footer-end-->