I'm mapping through an array and using destructuring.
const newArr = arr.map(({name, age}) => `${name} ${age}`)
The above errors as: Binding element 'name' implicitly has an 'any' type
Error goes away by adding:
const newArr = arr.map(({name, age}: { name: string; age: number }) => `${name} ${age}`)
The question is: Could I go about this with a more terse syntax and/or apply the needed types via an interface?
UPDATE: As a combination from the comments below and the suggestions by @grumbler_chester and @TimWickstrom
This was the more terse way I found to shorten my syntax:
Solution:
// User.tsx
interface User {
name: string
age: number
}
const newArr = arr.map(({name, age}: User) => `${name} ${age}`)
arrvariable typified?arr. Suggestions?