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.
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>
})
}
Create an interface for a Help object, and use it in the definition of your props:
interface Help {
name: string;
// other properties
}
interface Props {
help: Help[];
}
And then use Props when defining the component:
const Component = (props: Props) => {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With