#Property 'fields' does not exist on type 'never'

3 messages · Page 1 of 1 (latest)

sage garnet
#

Running into an issue with an error that says Property 'fields' does not exist on type 'never' with code that looks like ```interface GalleryCover {
fields: {
title: string;
date: string;
year: number;
image: {
fields: {
file: {
url: string;
};
};
};
link: string;
order: number;
};
contentTypeId: string;
}

const galleryCoverResponse = await contentfulClient.getEntries<GalleryCover>({
content_type: 'galleryCover',
//@ts-ignore
order: '-fields.order',
});

<MainLayout title="Knight Owls - Gallery">
<ImageHeader title="Gallery" background="/images/headers/gallery.webp" />
<h3>2023 Gallery</h3>
<GalleryAlbumLayout columns="3">
{
galleryCoverResponse.items
.filter((item) => item.fields.year === 2023)
.map((item) => (
<AlbumCover
event={item.fields.title}
date={item.fields.date}
image={item.fields.image.fields.file.url}
link={item.fields.link}
/>
))
}```

karmic basaltBOT
#

Hi @sage garnet. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

It seems like you're trying to fetch data from Contentful and use it in your Astro component. Based on the provided code, it looks like you're using the contentfulClient.getEntries<GalleryCover> method to fetch the data. However, the error you're encountering is related to TypeScript and the type of the fields property.

To resolve this issue, you can try the following:

  1. Make sure you have properly defined the GalleryCover interface and imported it into your Astro component.
  2. Ensure that the contentfulClient is correctly set up and imported.

Here's an example of fetching data from Contentful in Astro, extracted from the Astro documentation (https://docs.astro.build/en/guides/cms/contentful#fetching-data):

const { items } = await contentfulClient.getEntries<BlogPost>({
  content_type: "blogPost",
});
const pages = items.map((item) => ({
  params: { slug: item.fields.slug },
  props: {
    title: item.fields.title,
    content: documentToHtmlString(item.fields.content),
    date: new Date(item.fields.date).toLocaleDateString(),
  },
}));

In this example, the BlogPost interface is used to define the expected data structure. Make sure you have a similar setup for your GalleryCover interface.

If you're still encountering issues, please provide more information or refer to the Astro documentation (https://docs.astro.build/en/guides/cms/contentful) for further guidance on integrating Contentful with Astro.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Astro Documentation

Add content to your Astro project using Contentful as a CMS