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:
parent
acc8afbdda
commit
48161b77ca
2 changed files with 8 additions and 4 deletions
5
.changeset/eleven-planes-deliver.md
Normal file
5
.changeset/eleven-planes-deliver.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
MarkdownInstance: Persist frontmatter type into the return of `.default()`
|
|
@ -760,7 +760,7 @@ export interface MarkdownInstance<T extends Record<string, any>> {
|
||||||
getHeaders(): Promise<MarkdownHeader[]>;
|
getHeaders(): Promise<MarkdownHeader[]>;
|
||||||
default: () => Promise<{
|
default: () => Promise<{
|
||||||
metadata: MarkdownMetadata;
|
metadata: MarkdownMetadata;
|
||||||
frontmatter: MarkdownContent;
|
frontmatter: MarkdownContent<T>;
|
||||||
$$metadata: Metadata;
|
$$metadata: Metadata;
|
||||||
default: AstroComponentFactory;
|
default: AstroComponentFactory;
|
||||||
}>;
|
}>;
|
||||||
|
@ -817,10 +817,9 @@ export interface MarkdownParserResponse extends MarkdownRenderingResult {
|
||||||
* The `content` prop given to a Layout
|
* The `content` prop given to a Layout
|
||||||
* https://docs.astro.build/guides/markdown-content/#markdown-layouts
|
* https://docs.astro.build/guides/markdown-content/#markdown-layouts
|
||||||
*/
|
*/
|
||||||
export interface MarkdownContent {
|
export type MarkdownContent<T extends Record<string, any> = Record<string, any>> = T & {
|
||||||
[key: string]: any;
|
|
||||||
astro: MarkdownMetadata;
|
astro: MarkdownMetadata;
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* paginate() Options
|
* paginate() Options
|
||||||
|
|
Loading…
Reference in a new issue