Skip to content

Commit

Permalink
fix: Don’t require getCollection() filter to be a type guard
Browse files Browse the repository at this point in the history
Commit dabce6b (withastro#5970) broke the use
of a plain boolean filter.  Add an overload similar to TypeScript’s
Array#filter overload:

https://github.com/microsoft/TypeScript/blob/v4.9.4/lib/lib.es5.d.ts#L1442-L1453

Signed-off-by: Anders Kaseorg <[email protected]>
  • Loading branch information
andersk committed Jan 26, 2023
1 parent 322e059 commit 387e00e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-zoos-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Don’t require `getCollection()` filter to be a type guard
4 changes: 4 additions & 0 deletions packages/astro/src/content/template/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ declare module 'astro:content' {
collection: C,
filter?: (entry: CollectionEntry<C>) => entry is E
): Promise<E[]>;
export function getCollection<C extends keyof typeof entryMap>(
collection: C,
filter?: (data: CollectionEntry<C>) => unknown
): Promise<CollectionEntry<C>[]>;

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

0 comments on commit 387e00e

Please sign in to comment.