[Content collections] Support type guards on getCollection()
filter (#5970)
* fix: respect type guards from collection filter * chore: changeset
This commit is contained in:
parent
b53e0717b7
commit
dabce6b8c6
2 changed files with 8 additions and 3 deletions
5
.changeset/strong-hotels-sort.md
Normal file
5
.changeset/strong-hotels-sort.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add type guard support to filters on `getCollection()`
|
|
@ -44,10 +44,10 @@ declare module 'astro:content' {
|
||||||
): E extends ValidEntrySlug<C>
|
): E extends ValidEntrySlug<C>
|
||||||
? Promise<CollectionEntry<C>>
|
? Promise<CollectionEntry<C>>
|
||||||
: Promise<CollectionEntry<C> | undefined>;
|
: 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,
|
collection: C,
|
||||||
filter?: (data: CollectionEntry<C>) => boolean
|
filter?: (entry: CollectionEntry<C>) => entry is E
|
||||||
): Promise<CollectionEntry<C>[]>;
|
): Promise<E[]>;
|
||||||
|
|
||||||
type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer<
|
type InferEntrySchema<C extends keyof typeof entryMap> = import('astro/zod').infer<
|
||||||
Required<ContentConfig['collections'][C]>['schema']
|
Required<ContentConfig['collections'][C]>['schema']
|
||||||
|
|
Loading…
Reference in a new issue