utility-types icon indicating copy to clipboard operation
utility-types copied to clipboard

Add a "DeepMutable<T>" type

Open JShabtai opened this issue 5 years ago • 0 comments

Is your feature request related to a real problem or use-case?

An existing (possibly third party) type has nested readonly elements, but it would be handy to re-use that type and build up the final object which can only be done if the nested fields are updateable (i.e. not read only)

e.g.

interface MyInterface {
foo: {
readonly bar?: string;
}
}

It would be nice to be able to do something like

let x: MyInterface = {
foo: {
}
};

if (someCondition) {
x.foo.bar = 'someValue';
}

Describe a solution including usage in code example

Should work just like the other Deep* types, but making nested elements mutable like Mutable<T> already does.

Who does this impact? Who is this for?

All users who might be working with nested readonly types outside of their control (i.e. third party code)

Describe alternatives you've considered (optional)

Manually recreate the original type as non-readonly, but that's certainly not ideal.

Additional context (optional)

Could potentially use the features described in #151 and serve as a template/example for that refactoring.

Also, just want to say thanks for making and maintaining this library!

JShabtai avatar Oct 26 '20 14:10 JShabtai