Let's consider a scenario where I have the following mutable class:
class Foo {
constructor(public bar: any) { }
}
I am able to create instances of this class with readonly
properties like this:
const foo: Readonly<Foo> = new Foo(123);
foo.bar = 456; // error, cannot change the value of bar because it is readonly.
What if I want to do the opposite, where the class itself is immutable?
class Foo {
constructor(public readonly bar: any) { }
}
Then, can I create mutable versions of this class like so:
const foo: Mutable<Foo> = new Foo(123);
foo.bar = 456;
Is there a way to achieve this?