Reputation: 3409
I have a prop ("author") which is passed from a parent component. I have typed the propType("AuthorProps") but it say Property 'author' does not exist on type 'AuthorProps'
even though the structure look same.
AuthorProps:
export type AuthorProps = {
_id: string;
name: string;
slug: string;
authorId:string;
img: string;
createdAt?: string;
updatedAt?: string;
__v?: number;
}
author props logged:
{
_id: "61ffff139d0ad2a68738843a",
name: "Chetan Bagat",
slug: "chetan-bagat",
authorId: "0",
img: "https://img.etimg.com/thumb/msid-66099431,width-650,imgsize-149367,,resizemode-4,quality-100/chetan-bhagats-advice-for-students-its-all-about-knowing-how-to-market-yourself.jpg",
createdAt: "2022-02-06T17:02:11.490Z",
updatedAt: "2022-02-06T17:02:11.490Z",
__v: 0
}
Component:
function AuthorContainer({ author }: AuthorProps) { // }
Upvotes: 0
Views: 45
Reputation: 171
If you don't want to modify the type, this is recommended.
function AuthorContainer(author: AuthorProps) { // }
Upvotes: 0
Reputation: 17354
In your component, you use object destructuring and try to get {author}
from AuthorProps
. The definition of AuthorProps
does not contain this property.
Probably, you want to change your code to something like this:
export type AuthorProps = {
author: {
_id: string;
name: string;
slug: string;
authorId:string;
img: string;
createdAt?: string;
updatedAt?: string;
__v?: number;
}
}
Upvotes: 2