-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(mdx): add TypeScript types for Content components prop #14591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
4d9f8f5
2e2512c
28bc46b
f56dd3a
e728491
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/mdx': patch | ||
--- | ||
|
||
Adds TypeScript support for the `components` prop on MDX `Content` component when using `await render()`. Developers now get proper intellisense and type checking when passing custom components to override default MDX element rendering. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,33 @@ export interface MDXInstance<T extends Record<string, any>> | |
components: Record<string, AstroComponentFactory> | undefined; | ||
} | ||
|
||
/** | ||
* Props accepted by the MDX `Content` component when using `await render()`. | ||
* Allows passing custom components to override default MDX element rendering. | ||
* | ||
* @example | ||
* ```astro | ||
* --- | ||
* import { getEntry, render } from 'astro:content'; | ||
matthewp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* const entry = await getEntry('blog', 'post'); | ||
* const { Content } = await render(entry); | ||
* --- | ||
* <Content components={{ h1: MyCustomH1, img: MyImage }} /> | ||
matthewp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* ``` | ||
*/ | ||
export interface MDXContentProps { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling @ArmandPhilippot -- I don't think we document Markdown or MDX types, really. So, nothing to update, but is this something we should have? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it's useful to document these types like we do the ones where we expect users to import them into their project. They seem more useful internally than in a user project. And I don't recall seeing users complain those types are not documented/would have been useful. We document So, I think it's fine as it is! |
||
/** Custom components to use for MDX elements (e.g., h1, h2, img, a, etc.) */ | ||
components?: Record<string, AstroComponentFactory>; | ||
/** Any additional props to pass to the MDX content */ | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* The MDX `Content` component returned from `await render()`. | ||
* Extends `AstroComponentFactory` with typed props for better developer experience. | ||
*/ | ||
export type MDXContent = AstroComponentFactory & ((props?: MDXContentProps) => any); | ||
|
||
export interface MarkdownLayoutProps<T extends Record<string, any>> { | ||
frontmatter: { | ||
file: MarkdownInstance<T>['file']; | ||
|
Uh oh!
There was an error while loading. Please reload this page.