I have 2 different type of complex object. I want to assign one of them to other by mapping attributes. How can I achieve it?
interface IClassA{
attribute1: string; //same with IClassB
attribute2: string; //same with IClassB
attribute3: number; //different type different mane with IClassB
};
interface IClassB{
attribute1: string;
attribute2: string;
attr3: string;
};
var obj1: IClassA= {
attribute1: 'xxx',
attribute2: 'yyy',
attribute3: 5
};
var obj2: IClassB;
console.log(obj1);
Output is :
[LOG]: {
"attribute1": "xxx",
"attribute2": "yyy",
"attribute3": 5
}
When I want to make obj2 written, it needs to be like:
"attribute1": "xxx", "attribute2": "yyy", "attr3": "5" }
How can I assign like that obj2 = obj1 .. I need to map attributes by attributes, what is the best way?
I dont want yo use that notation(ASSUME that I have n attribute with same name, just 1 attribute with different name)
obj2.attribute1 = obj1.attribute1; .....