I am trying to figure out why my code is telling me that my mapped data that has a property of 'name' is of type never. I am already declaring the commentsData in the interface but there is obviously an error occuring there.
Please see my code below:
interface IProps {
commentsData: []
}
const CommentList: React.FC<IProps> = ({ commentsData }: IProps) => {
return (
<div>
{commentsData.map(comment => {
return (
<div>
{comment.name}
</div>
)
})}
</div>
)
}
export const getStaticProps = async ()=> {
const data = await fetch('https://jsonplaceholder.typicode.com/comments')
.then((res) => res.json())
.then((data) => data);
return {
props: {
commentsData: data
}
}
}
export default CommentList;
And here is the image with the error that Typescript is throwing:

Anyone here ever saw this error? And how did you solve it. Thanks for any help!

commentsDatais an array of. Looks like it's an array of object, so you need to tell Typescript what those objects look like in your interface, e.g.commentsData: { name: string }[]