While iterating through an array, I am utilizing destructuring.
const newArr = arr.map(({name, age}) => `${name} ${age}`)
An error occurs in the above code stating: Binding element 'name' implicitly has an 'any' type
To resolve this error, the following modification can be made:
const newArr = arr.map(({name, age}: { name: string; age: number }) => `${name} ${age}`)
Now, the question arises: Is there a more concise way to achieve the same result and/or apply the necessary types using an interface?
UPDATE: Integrating suggestions from comments and recommendations by @grumbler_chester and @TimWickstrom
I have discovered a shorter and cleaner approach to streamline my syntax:
Solution:
// User.tsx
interface User {
name: string
age: number
}
const newArr = arr.map(({name, age}: User) => `${name} ${age}`)