Skip to content

Commit

Permalink
Update the types to accept both raw string and known value
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Jan 18, 2023
1 parent 401df58 commit d41cc2f
Showing 1 changed file with 3 additions and 3 deletions.
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 @@ -34,11 +34,11 @@ declare module 'astro:content' {
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
type ValidEntrySlug<C extends EntryMapKeys> = AllValuesOf<typeof entryMap[C]>['slug'];

export function getEntryBySlug<C extends keyof typeof entryMap>(
export function getEntryBySlug<C extends keyof typeof entryMap, E extends ValidEntrySlug<C> | (string & {})>(
collection: C,
// Note that this has to accept a regular string too, for SSR
entrySlug: ValidEntrySlug<C> | string
): entrySlug extends ValidEntrySlug<C> ? Promise<CollectionEntry<C>> : Promise<CollectionEntry<C> | undefined>;
entrySlug: E
): E extends ValidEntrySlug<C> ? Promise<CollectionEntry<C>> : Promise<CollectionEntry<C> | undefined>;
export function getCollection<
C extends keyof typeof entryMap,
>(
Expand Down

0 comments on commit d41cc2f

Please sign in to comment.