Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/mdx-content-component-types.md
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.
29 changes: 29 additions & 0 deletions packages/astro/src/types/public/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ 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';
* import MyCustomH1 from '../components/CustomHeading.astro';
* import MyImage from '../images/MyImage.jpg';
* const entry = await getEntry('blog', 'post');
* const { Content } = await render(entry);
* ---
* <Content components={{ h1: MyCustomH1, img: MyImage }} />
* ```
*/
export interface MDXContentProps {
/** 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'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare module 'astro:content' {
interface Render {
'.mdx': Promise<{
Content: import('astro').MarkdownInstance<{}>['Content'];
Content: import('astro').MDXContent;
headings: import('astro').MarkdownHeading[];
remarkPluginFrontmatter: Record<string, any>;
components: import('astro').MDXInstance<{}>['components'];
Expand Down
Loading