I get the correct data here, but the attributes part of the variable is marked red by vscode with this error: Property 'attributes' does not exist on type 'Strapi4ResponseData<Hero>[]'.ts(2339)
How does your Hero type look like ? Because technically itâs not a hero type itâs a DATA (Or whatever you want to call the generic response) type so something like this ?
So to try explain it the âdataâ interface I created has a Hero one containing what is part of the Hero.
The response you get back contains, data with attributes. Which is NOT Hero
The const myData is not needed btw also you need to export the interface
const x = await fetchApi<collectionProps[]>({
endpoint:'collection?populate=*',
wrappedByKey: 'data',
});
Only works with collection types not single types because of the bracktes in the collectionProps, youâre indicating that the data collected from the API is an array, and Strapi single types return an object.
If you quit the brackets, VS code wonât give you the Property 'attributes' does not exist on type 'Strapi4ResponseData<Hero>[]'.ts(2339) problem.
Maybe itâs kind of obvious but it was a big headache for me, hope this help someone!