Skip to content

Commit

Permalink
[Content collections] Support type guards on getCollection() filter (
Browse files Browse the repository at this point in the history
…#5970)

* fix: respect type guards from collection filter

* chore: changeset
  • Loading branch information
bholmesdev authored Jan 25, 2023
1 parent b53e071 commit dabce6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-hotels-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Add type guard support to filters on `getCollection()`
6 changes: 3 additions & 3 deletions packages/astro/src/content/template/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ declare module 'astro:content' {
): E extends ValidEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
export function getCollection<C extends keyof typeof entryMap>(
export function getCollection<C extends keyof typeof entryMap, E extends CollectionEntry<C>>(
collection: C,
filter?: (data: CollectionEntry<C>) => boolean
): Promise<CollectionEntry<C>[]>;
filter?: (entry: CollectionEntry<C>) => entry is E
): Promise<E[]>;

type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer<
Required<ContentConfig['collections'][C]>['schema']
Expand Down

0 comments on commit dabce6b

Please sign in to comment.