diff --git a/.changeset/rotten-dogs-hide.md b/.changeset/rotten-dogs-hide.md new file mode 100644 index 000000000..b167279aa --- /dev/null +++ b/.changeset/rotten-dogs-hide.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Update `getCollection()` filter to support type guards _or_ unknown values diff --git a/packages/astro/src/content/internal.ts b/packages/astro/src/content/internal.ts index 8d20aa184..2002aa76d 100644 --- a/packages/astro/src/content/internal.ts +++ b/packages/astro/src/content/internal.ts @@ -40,7 +40,7 @@ export function createGetCollection({ collectionToEntryMap: CollectionToEntryMap; collectionToRenderEntryMap: CollectionToEntryMap; }) { - return async function getCollection(collection: string, filter?: () => boolean) { + return async function getCollection(collection: string, filter?: (entry: any) => unknown) { const lazyImports = Object.values(collectionToEntryMap[collection] ?? {}); const entries = Promise.all( lazyImports.map(async (lazyImport) => { diff --git a/packages/astro/src/content/template/types.d.ts b/packages/astro/src/content/template/types.d.ts index 628f5d18d..f14a541f1 100644 --- a/packages/astro/src/content/template/types.d.ts +++ b/packages/astro/src/content/template/types.d.ts @@ -48,6 +48,10 @@ declare module 'astro:content' { collection: C, filter?: (entry: CollectionEntry) => entry is E ): Promise; + export function getCollection( + collection: C, + filter?: (entry: CollectionEntry) => unknown + ): Promise[]>; type InferEntrySchema = import('astro/zod').infer< Required['schema']