Update content-types.template.d.ts (#8010)

Provides more useful information when hovering variables typed with CollectionEntry<"collectionName"> 

* Does not change the functionality of existing code

* Flatten<AnyEntryMap[C]> is the same as AnyEntryMap[C][keyof AnyEntryMap[C]]

* Both will produce a union of all note entry types within the "collectionName" key
This commit is contained in:
Oliver Speir 2023-08-10 06:39:36 -06:00 committed by GitHub
parent 1e3c9f515b
commit 4c9d1cb8f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,7 +10,9 @@ declare module 'astro:content' {
declare module 'astro:content' { declare module 'astro:content' {
export { z } from 'astro/zod'; export { z } from 'astro/zod';
export type CollectionEntry<C extends keyof AnyEntryMap> = AnyEntryMap[C][keyof AnyEntryMap[C]];
type Flatten<T> = T extends { [K: string]: infer U } ? U : never;
export type CollectionEntry<C extends keyof AnyEntryMap> = Flatten<AnyEntryMap[C]>;
// TODO: Remove this when having this fallback is no longer relevant. 2.3? 3.0? - erika, 2023-04-04 // TODO: Remove this when having this fallback is no longer relevant. 2.3? 3.0? - erika, 2023-04-04
/** /**