Reputation: 1164
here is my code :
import * as React from 'react';
export const Suggestions = (props:any) => {
const options = props.results.map((r: { id: number ; name: string; }) => (
<li key={r.id}>
{r.name}
</li>
))
return <ul>{options}</ul>
}
export default Suggestions
but i would like to define r as an array of { id: number ; name: string; }
not just { id: number ; name: string; }
Regards
Upvotes: 1
Views: 34
Reputation: 115282
You can use []
at the end of the inline interface definition to make it as an array type.
const options = props.results.map((r: { id: number ; name: string; }[]) => (
Array<T>
with the inline interface defenition.
const options = props.results.map((r: Array<{ id: number ; name: string; }>) => (
Upvotes: 2