diff --git a/.changeset/sharp-clouds-begin.md b/.changeset/sharp-clouds-begin.md new file mode 100644 index 0000000000..12b857a5a2 --- /dev/null +++ b/.changeset/sharp-clouds-begin.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Added additional generated typings for the content layer diff --git a/packages/astro/templates/content/types.d.ts b/packages/astro/templates/content/types.d.ts index 14b57053c3..30f4286b80 100644 --- a/packages/astro/templates/content/types.d.ts +++ b/packages/astro/templates/content/types.d.ts @@ -31,6 +31,15 @@ declare module 'astro:content' { ContentEntryMap[C] >['slug']; + export type ReferenceDataEntry = { + collection: C; + id: E; + } + export type ReferenceContentEntry | (string & {}) = string> = { + collection: C; + slug: E; + } + /** @deprecated Use `getEntry` instead. */ export function getEntryBySlug< C extends keyof ContentEntryMap, @@ -61,19 +70,13 @@ declare module 'astro:content' { export function getEntry< C extends keyof ContentEntryMap, E extends ValidContentEntrySlug | (string & {}), - >(entry: { - collection: C; - slug: E; - }): E extends ValidContentEntrySlug + >(entry: ReferenceContentEntry): E extends ValidContentEntrySlug ? Promise> : Promise | undefined>; export function getEntry< C extends keyof DataEntryMap, E extends keyof DataEntryMap[C] | (string & {}), - >(entry: { - collection: C; - id: E; - }): E extends keyof DataEntryMap[C] + >(entry: ReferenceDataEntry): E extends keyof DataEntryMap[C] ? Promise : Promise | undefined>; export function getEntry< @@ -99,16 +102,10 @@ declare module 'astro:content' { /** Resolve an array of entry references from the same collection */ export function getEntries( - entries: { - collection: C; - slug: ValidContentEntrySlug; - }[], + entries: ReferenceContentEntry>[], ): Promise[]>; export function getEntries( - entries: { - collection: C; - id: keyof DataEntryMap[C]; - }[], + entries: ReferenceDataEntry[], ): Promise[]>; export function render( @@ -120,14 +117,8 @@ declare module 'astro:content' { ): import('astro/zod').ZodEffects< import('astro/zod').ZodString, C extends keyof ContentEntryMap - ? { - collection: C; - slug: ValidContentEntrySlug; - } - : { - collection: C; - id: keyof DataEntryMap[C]; - } + ? ReferenceContentEntry> + : ReferenceDataEntry >; // Allow generic `string` to avoid excessive type errors in the config // if `dev` is not running to update as you edit.