Reputation: 2272
I know, for multiple arguments or single argument with type, we have to parenthesize arguments of an arrow function. e.g.
.map( (arg1, arge2) => returnValue )
or .map( (arg1: ArgType) => returnValue )
And if we intend to return a json literal from shorter syntax arrow function, we've to parenthesize it. e.g.
.map( (arg1, arge2) => ({ a: 1, b: 2}) )
But, what does the following do?
.map( ({ value }) => value )
I stumbled across it in a TypeScript codebase, don't yet know if it is also supported in ES6.
Upvotes: 2
Views: 118
Reputation: 250056
This is part of destructuring in ES2015 it is basically equivalent to
let arr = [{ value: "" }]
arr.map(({ value }) => value )
// same as
arr.map(o => { let value = o.value; return value; } )
Upvotes: 4