From e36f310c2c3d22545ca81187fac282307dc98cb6 Mon Sep 17 00:00:00 2001 From: matthewp Date: Thu, 19 Jan 2023 13:36:12 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/content/internal.ts | 8 ++++---- packages/astro/src/content/template/types.d.ts | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/astro/src/content/internal.ts b/packages/astro/src/content/internal.ts index 550f6665a..8d20aa184 100644 --- a/packages/astro/src/content/internal.ts +++ b/packages/astro/src/content/internal.ts @@ -80,15 +80,15 @@ export function createGetEntryBySlug({ // This is not an optimized lookup. Should look into an O(1) implementation // as it's probably that people will have very large collections. const entries = await getCollection(collection); - let candidate: typeof entries[number] | undefined = undefined; - for(let entry of entries) { - if(entry.slug === slug) { + let candidate: (typeof entries)[number] | undefined = undefined; + for (let entry of entries) { + if (entry.slug === slug) { candidate = entry; break; } } - if(typeof candidate === 'undefined') { + if (typeof candidate === 'undefined') { return undefined; } diff --git a/packages/astro/src/content/template/types.d.ts b/packages/astro/src/content/template/types.d.ts index 5b4dc874b..81ea9a95e 100644 --- a/packages/astro/src/content/template/types.d.ts +++ b/packages/astro/src/content/template/types.d.ts @@ -32,16 +32,19 @@ declare module 'astro:content' { type EntryMapKeys = keyof typeof entryMap; type AllValuesOf = T extends any ? T[keyof T] : never; - type ValidEntrySlug = AllValuesOf['slug']; + type ValidEntrySlug = AllValuesOf<(typeof entryMap)[C]>['slug']; - export function getEntryBySlug | (string & {})>( + export function getEntryBySlug< + C extends keyof typeof entryMap, + E extends ValidEntrySlug | (string & {}) + >( collection: C, // Note that this has to accept a regular string too, for SSR entrySlug: E - ): E extends ValidEntrySlug ? Promise> : Promise | undefined>; - export function getCollection< - C extends keyof typeof entryMap, - >( + ): E extends ValidEntrySlug + ? Promise> + : Promise | undefined>; + export function getCollection( collection: C, filter?: (data: CollectionEntry) => boolean ): Promise[]>;