I'm upgrading a site from using Markdown files in src/pages to content collections. The blog page uses Pagination to generate a list of pages. The existing code (which I didn't write, so I'm only somewhat familiar with it) starts with the pagination function, which passes its results to a <Paginator /> component, which passes each Page<T>.data[] element to a <PostEmbed /> element, which creates each list item on the page.
This is the pagination function:
// src/pages/blog/[page].astro
export async function getStaticPaths({ paginate }: any) {
const allPosts = await getCollection("blog")
sortByDescending(allPosts, (post) => new Date(post.data.date));
return paginate(allPosts, { pageSize: 5 });
}
The docs say that the paginate function returns its data as Page<T>, so I've typed Astro.props as follows:
// src/pages/blog/[page].astro
export interface Props {
page: Page<CollectionEntry<"blog">>
}
Then I've passed the prop to the paginator as <Paginator page={Astro.props.page} /> and <Paginator />'s Props are typed as above.
In Paginator.astro, each entry in the collection is mapped to a <PostEmbed />:
// Paginator.astro
{page.data.map((post) => <PostEmbed {post} />)}
And its Props are typed as follows:
interface Props {
post: CollectionEntry<"blog">
}
As far as I can tell, this is typed correctly, but when I try visit the page in the dev server, it fails with [ERROR] Cannot destructure property 'title' of 'post.data' as it is undefined.. I tried tracing the data's path through the stack with logging statements like
console.log("PostEmbed received: " + JSON.stringify(Astro.props))
to see what Astro.props.post is actually sending, but nothing was printed to the console, so I'm not really sure where to go next.