I have an array of members in Typescript.
const members = [
{
name: 'John Lennon',
id: 1
},
{
name: 'Led Zeppelin',
id: 2
},
{
name: 'Freddie Mercury',
id: 3
}
];
When I try to map over it and add key
members.map(member => {
member.designation = 'Singer';
return member;
});
It successfully overwrites an array and add key designation. But when I try doing the same thing using Object spread operator.
members.map(member => ({
...member,
designation: 'Singer'
}));
It successfully compiles with no error, but at the same time does not map the key designation over my members array.
Is it the correct way to do, or am I missing something and it is just a problem with Typescript Object spread operation.