How do I use the map
function to iterate over an array and return a new object without triggering TSLint warnings?
TSLint suggests simplifying the arrow function by removing curly braces, 'return' keyword, and adding parentheses around the object literal.
Consider the example of the user object:
class User {
constructor(
public id: number,
public first_name: string,
public last_name: string,
public gender: Date,
public location: number,
)
}
When applying this transformation:
const simple_users = users.map(u => { return { name: u.name, id: u.id} });
You may encounter the following warning:
arrow-return-shorthand
.