Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollectionEntry is any?

Tags:

astrojs

I have Content Collections enabled and I have the following /content/config.ts:

import { z, defineCollection } from "astro:content";

const articlesCollection = defineCollection({
    schema: z.object({
      title: z.string(),
      description: z.string(),
      tags: z.array(z.string()).optional()
    })
});

const postsCollection = defineCollection({
  schema: z.object({
    title: z.string(),
    description: z.string().optional(),
    tags: z.array(z.string()).optional(),
    publishDate: z.date()
  })
});

export const collections = {
    'articles': articlesCollection,
    'posts': postsCollection
};

I want to retrieve a type of articles' frontmatter. In my layout, I have the following fence:

---
import type { CollectionEntry } from 'astro:content';

interface Props {
    slug: string;
    frontmatter: CollectionEntry<'articles'>['data']; // any?
}

const { frontmatter, slug } = Astro.props;
---

It seems that CollectionEntry<'articles'>['data'] resolves to any. Why is that?

like image 548
mnj Avatar asked Sep 02 '25 16:09

mnj


1 Answers

In instances where everything is configured correctly, it might be caused by a stale cache. Running rm -rf ./.astro/ and then letting the .astro directory regenerate (when dev or build is run) should fix that particular case.

like image 140
Mina Avatar answered Sep 05 '25 15:09

Mina