'Property 'name' does not exist on type 'object' TypeScript

I have this array.map function:

{props.help.map((e, i) => {
return <a key={i}>{e.name}</a>
})}

{e} object have 'name' and 'href' keys

i got "Property 'name' does not exist on type 'object'" (typescript)

I am beginner in typescript.



Solution 1:[1]

You need to either cast the object to type any or the best practice is to add a type definition.

interface ExampleObject {
    name: string;
}
{
  props.help.map((e: ExampleObject, i) => {
    return <a key={i}>{e.name}</a>
  })
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S. Singh