Let me start with an example:
let john = {
name: "John",
age: 21
}
let newAge = {
age: 22
}
john = {...john , ...newAge};
By doing the above I can update john
by passing the newAge
object with the dot notation (spread operator). The advantage here is that it is easy to extend this behavior and easily update the values of an object by passing the updated values in partial object.
I want to do something similar with a class.
interface IPerson {
name?: string;
age?: number;
class Person implements IPerson {
update(value: IPerson) {
// somehow make it work?
}
}
I just don't see how I can do this with this
.
Is this possible?