【发布时间】:2022-08-16 07:37:57
【问题描述】:
不知道为什么post props有错误
错误描述为Property \'body\' does not exist on type \'never\'
InferGetStaticPropsType 即使我指定了类型也会有错误吗?
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;
当我检查console.log(post)时,它的结构如下。
{
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\'
}
```
-
不应该是
const Detail = (post: InferGet.....吗? -
好像类型坏了。你可能想搜索他们的 GitHub 问题,如果你没有找到任何东西,你可以打开你自己的。
标签: typescript next.js