i want to add an object into another object using typescript.
below is data1
data1 = {firstDetails: {...}}
data1 = {
firstDetails: {
id: '1',
name: 'first'
description: 'description'
//other fields,
}
}
and there is data2 like below
data2 {secondDetails: {...}}
const data2 = {
secondDetails: {
id: '1',
items: [],
values: [],
}
}
now i want to remove property id from secondDetails and then take items and values from data2 and add it to data1.
so the expected output is like below
{
firstDetails: {
id: '1',
name: 'first',
description: 'description',
items: [],
values: [],
}
}
i have tried like below,
const formattedData2 = formattedData2.secondDetails;
const without_id = omit(formattedData2, 'id')
data1.firstDetails = Object.assign(data1.firstDetails, without_id);
but this gives error in dat1.firstDetails in the last line. it says variable data has implicitly any type.
could someone help me fix this. how can i put one object into another using typescript. thanks.