Skip to content

Commit

Permalink
Fix unintentional missing type data in MarkdownInstance (#3397)
Browse files Browse the repository at this point in the history
* 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<string, any>`. 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.
  • Loading branch information
happycollision authored Jun 14, 2022
1 parent acc8afb commit 48161b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-planes-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

MarkdownInstance: Persist frontmatter type into the return of `.default()`
7 changes: 3 additions & 4 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export interface MarkdownInstance<T extends Record<string, any>> {
getHeaders(): Promise<MarkdownHeader[]>;
default: () => Promise<{
metadata: MarkdownMetadata;
frontmatter: MarkdownContent;
frontmatter: MarkdownContent<T>;
$$metadata: Metadata;
default: AstroComponentFactory;
}>;
Expand Down Expand Up @@ -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<T extends Record<string, any> = Record<string, any>> = T & {
astro: MarkdownMetadata;
}
};

/**
* paginate() Options
Expand Down

0 comments on commit 48161b7

Please sign in to comment.