I've been working on converting the following JavaScript code to TypeScript:
users.map( item => (
{ name: item.name,
email: item.email,
...item.user
}
));
The structure of users
looks like this:
users = [
{
name: "John",
email: "john@msn"
user: {
age: 56,
gender: "Male",
address: "...",
sport: "basketball"
}
},
...
]
I'm aiming to transform it into:
users = [
{
name: "John",
email: "john@msn",
age: 56,
gender: "Male",
address: "...",
sport: "basketball"
},
...
]
I attempted to declare the type of the parameter right after the parameter and the type of the return value before the arrow:
users.map( (item:object):object => (
{ name: item.name,
email: item.email,
...item.user
}
));
Unfortunately, this approach didn't work as expected.
Any suggestions or hints?