I want to generate a list of table rows by using forEach()
in Typescript and React. I get Property 'forEach' does not exist on type
when using the code below. Does anyone know how to fix this? Shouldn't I be able to use forEach() on persons as it is an array of PersonInterfaces?
interface PersonList {
[index: number]: PersonInterface
}
interface PersonInterface {
name: string,
age: number
}
const persons:PersonList = [
{
name: 'John',
age: 25,
}, {
name: 'Jill',
age: 28,
}
];
export default function Table() {
return (
<table>
{
persons.forEach(person => {
return (
<tr>
<td>{person.name}</td>
</tr>
);
})
}
</table>
);
}