MDX lets you write blog posts in Markdown while embedding interactive components. Adding TypeScript ensures those components are type-safe. Together, they streamline content updates and prevent runtime errors.
npm install @astrojs/mdx
2. Enable in Astro config
// astro.config.mjs import mdx from ‘@astrojs/mdx’;
export default { integrations: [mdx()], };
⸻
Place posts under src/content/posts/hello.mdx:
This is regular Markdown.
⸻
// src/components/MyAlert.tsx interface Props { message: string } export default function MyAlert({ message }: Props) { return
• Import in MDX without losing type checks:
import MyAlert from ‘../components/MyAlert.tsx’;
⸻
⸻
Takeaway
MDX plus TypeScript in Astro delivers a best-of-both-worlds solution: easy authoring and reliable, type-checked components. It’s ideal for blogs, documentation, or any content-driven site.
©Copyright 2020 by Avid Tech Usa. Built with ♥ by Omar Madjitov.