I am learning Typescript and I am changing existing files in a React app from js to tsx.
For the code below I pass in an array of posts.
I've change the file extension to .tsx and I then change the signature from
export default function PostList ({ posts = [] }) {
to
export default function PostList ({ posts = [] }: { posts: array}) {
but I get
TypeScript error: Cannot find name 'array'. TS2304
Rest of the code:
import React from 'react'
import Post from './Post'
export default function PostList ({ posts = [] }: { posts: array}) {
const sortedPosts = posts.sort((postA,postB) => {
return Date.parse(postB.created) - Date.parse(postA.created);
})
return (
<div>
{sortedPosts.map((p, i) => (
<React.Fragment key={'post-' + i}>
<Post {...p} />
<hr />
</React.Fragment>
))}
</div>
)
}