Make a Read-Only Object Writable Again

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Export a type Mutable<T> that removes readonly from every property of T (keeping optional ones optional), and write thaw(obj): return a shallow copy of obj that can be changed, typed as Mutable of its input. The copy must not be frozen even when obj is, and its properties must keep their types, so writing a value of the wrong type or a property obj doesn't have is still a type error.

Your code must pass

  • Copies every property
  • Returns a writable copy
  • Has no type errors
  • Removes readonly from every property
  • Keeps each property's type