类型 {} 不可分配给类型"通知[]",类型通知中缺少以下属性



我是Typescript的新手,我正在制作一个功能齐全的instagram克隆。最近有一个想法,对于通知来说,有一个具有不同属性的对象数组来渲染会更容易。我从json中导入了数据,但是现在我收到了这个错误。

JSON数据

{"username": "kahlilsassa ",
"profileImage":
"https://pbs.twimg.com/profile_images/1587301092680941569/B2GsgnBg_400x400.jpg",
"seen": true,
"followed": true,
"verified": false,
"datePosted": "2022-11-01:11:09"

**Notification Component**
interface Props {
notifications: Notification[] | null;
}
export interface Notification {
requested: Array<requested> | null;
username: string;
profileImage: string;
seen: boolean;
followed: boolean;
verified: boolean;
datePosted: string;
}
}, 
**Home Component** 
<Modal
active={notifications}
setActive={setNotifications}
title="Notifications">
<div className="divider">
<Notifications notifications={data1} /> <----ERROR IS HERE
</div>
</Modal>

它只是说你传递的数据是一个Object,你应该像这样传递数组notifications={[data1]}

**Home Component** 
<Modal
active={notifications}
setActive={setNotifications}
title="Notifications">
<div className="divider">
<Notifications notifications={[data1]} /> <----ERROR IS HERE
</div>
</Modal>

最新更新