From dfc0285bb531ee5719a2b7dd66bb755c767ce5b2 Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 24 Jan 2023 17:02:32 -0500 Subject: [PATCH 1/2] fix: respect type guards from collection filter --- packages/astro/src/content/template/types.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/astro/src/content/template/types.d.ts b/packages/astro/src/content/template/types.d.ts index 81ea9a95e450..628f5d18df12 100644 --- a/packages/astro/src/content/template/types.d.ts +++ b/packages/astro/src/content/template/types.d.ts @@ -44,10 +44,10 @@ declare module 'astro:content' { ): E extends ValidEntrySlug ? Promise> : Promise | undefined>; - export function getCollection( + export function getCollection>( collection: C, - filter?: (data: CollectionEntry) => boolean - ): Promise[]>; + filter?: (entry: CollectionEntry) => entry is E + ): Promise; type InferEntrySchema = import('astro/zod').infer< Required['schema'] From 18f6ea37fb0558e3611715fe3a1a90fc412e655b Mon Sep 17 00:00:00 2001 From: bholmesdev Date: Tue, 24 Jan 2023 17:14:38 -0500 Subject: [PATCH 2/2] chore: changeset --- .changeset/strong-hotels-sort.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/strong-hotels-sort.md diff --git a/.changeset/strong-hotels-sort.md b/.changeset/strong-hotels-sort.md new file mode 100644 index 000000000000..7b674aef566d --- /dev/null +++ b/.changeset/strong-hotels-sort.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Add type guard support to filters on `getCollection()`