From 48161b77caf35a9f3c285c0c7fbb9d8a937241c9 Mon Sep 17 00:00:00 2001 From: Don Denton Date: Tue, 14 Jun 2022 16:20:13 -0400 Subject: [PATCH] Fix unintentional missing type data in `MarkdownInstance` (#3397) * Update MarkdownInstance type The return of the `default` function includes the same `frontmatter` data as the parent object, merged with the `astro` data. The inclusion of that frontmatter type was previously not recognized by TS, and fell back to a `Record`. This change persists the more accurate type, as the runtime code does. * fixup! Update MarkdownInstance type (This change is what I'd personally do, but I don't really know how you expect people to use `MarkdownContent` in practice, or if there is some deeper benefit you wish to exploit by leaving it as an interface instead of a type. --- .changeset/eleven-planes-deliver.md | 5 +++++ packages/astro/src/@types/astro.ts | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 .changeset/eleven-planes-deliver.md diff --git a/.changeset/eleven-planes-deliver.md b/.changeset/eleven-planes-deliver.md new file mode 100644 index 000000000..c3d44b459 --- /dev/null +++ b/.changeset/eleven-planes-deliver.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +MarkdownInstance: Persist frontmatter type into the return of `.default()` diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 137fb3b85..7dd341d6f 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -760,7 +760,7 @@ export interface MarkdownInstance> { getHeaders(): Promise; default: () => Promise<{ metadata: MarkdownMetadata; - frontmatter: MarkdownContent; + frontmatter: MarkdownContent; $$metadata: Metadata; default: AstroComponentFactory; }>; @@ -817,10 +817,9 @@ export interface MarkdownParserResponse extends MarkdownRenderingResult { * The `content` prop given to a Layout * https://docs.astro.build/guides/markdown-content/#markdown-layouts */ -export interface MarkdownContent { - [key: string]: any; +export type MarkdownContent = Record> = T & { astro: MarkdownMetadata; -} +}; /** * paginate() Options