属性'Post'在类型"内部属性"上不存在。或不可分配给类型"内部属性"


import Head from 'next/head';
import { PostCard, Categories, PostWidget } from '../components'
const posts = [
{
title: "React Testing",
excerpt: "Learn React Testing"
},
{
title: "React with Tailwind",
excerpt: "Learn React with Tailwind",
},
];

export default function Home() {
return (
<div className="container mx-auto px-10 mb-8">
<Head>
<title>Create Next App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<div className="grid grid-cols-1 lg:grid-cols-12 gap-12">
<div className="lg:col-span-8 col-span-1">
{posts.map((post) => <PostCard post={post} key={post.title} />)}

</div>
<div className="lg:col-span-4 col-span-1">
<div className="lg:sticky relative top-8">
<PostWidget />
<Categories />
</div>
</div>
</div>
</div>
)}

错误为

类型"{post:{title:string;extract:string;};key:string;}'不可分配给类型"IntrnsicAttributes"。类型"IntrnsicAttributes"上不存在属性"post"。ts(2322(

它抱怨key道具是string,而它是用object传递的。。

将其更改为以下内容,键应该是列表中的某个独特道具

<div className="lg:col-span-8 col-span-1">
{posts.map((post) => <PostCard post={**post.some_unique_propname**} key={post.title} />)}
</div>

最新更新