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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With