I'm puzzled by an error that occurred with post props. The error message reads as follows:
Property 'body' does not exist on type 'never'
.
https://i.stack.imgur.com/zYlxc.png
Even when I specify the type, can there still be an error with InferGetStaticPropsType<typeof getStaticPaths>?
interface IParams {
params: {
slug: string;
};
}
export const getStaticPaths = async () => {
return {
paths: allPosts.map((p) => ({ params: { slug: p._raw.flattenedPath } })),
fallback: false,
};
};
export async function getStaticProps({ params }: IParams) {
const post: Post = allPosts.find(
(post) => post._raw.flattenedPath === params.slug
) as Post;
console.log(post);
return {
props: {
post,
},
};
}
export default Detail;
When I inspect console.log(post)
, its structure looks like this:
{
title: 'good ! ',
date: '2022-08-10T00:00:00.000Z',
description: 'this is description',
tags: 'Typescript',
body: {
raw: '## hello world',
code: '' },
_id: 'second.mdx',
_raw: {
sourceFilePath: 'second.mdx',
sourceFileName: 'second.mdx',
sourceFileDir: '.',
contentType: 'mdx',
flattenedPath: 'second'
},
type: 'Post'
}