Reputation: 29
I'm trying to pass objects from the array to components.
But it says that property title doesn't exist in this type.
Also, the console log acts weirdly. What am I doing wrong?
Upvotes: 2
Views: 5211
Reputation: 185445
You declare the property to be an object
which specifies just about nothing, so of course the compiler will not know that there is a title
. You have to be more specific (or tell the compiler to accept anything using any
which is not recommended).
You can define a named interface or define the type inline:
export let data: Data;
interface Data { title: string, desc: string, img: string, prize: number }
export let data: { title: string, desc: string, img: string, prize: number };
(Btw, prize
should probably be price
.)
Upvotes: 3