A scenario involves creating two distinct types:
export class GenericType {
public id: string;
public property: string;
public name: string;
}
export class SpecificType extends GenericType {
public value: string;
}
Let's say we have two variables A: GenericType
and B: SpecificType
. The objective is to transfer all values from A
to B
, as well as assign a specific value to B
. However, manual assignment of each property from A
to B
is not desired.
let varA: GenericType = {
id: '123',
property: 'example',
name: 'example variable',
};
let varB: SpecificType = new SpecificType();
varB = varA; // Cannot directly assign here.
varB.value = 'new value';