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 (#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 <andersk@mit.edu>
  • Loading branch information
andersk committed Jan 26, 2023
1 parent 322e059 commit 6588286
Showing 1 changed file with 4 additions and 0 deletions.
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 6588286

Please sign in to comment.