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<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.
This commit is contained in:
Don Denton 2022-06-14 16:20:13 -04:00 committed by GitHub
parent acc8afbdda
commit 48161b77ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
MarkdownInstance: Persist frontmatter type into the return of `.default()`

View file

@ -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;
}>;
@ -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