Fumadocs TypeScript Integration

5.2.6 · active · verified Tue Apr 21

fumadocs-typescript is a specialized integration package within the Fumadocs ecosystem, providing robust TypeScript support for documentation projects built with Next.js. It enables developers to define and enforce type-safety for MDX frontmatter, ensuring consistency and reducing errors in content authoring. The package is currently at version 5.2.6. While its specific release cadence isn't independently clear, it often updates in conjunction with major releases of `fumadocs-core` and `fumadocs-ui`, which demonstrate frequent maintenance and improvements. Its key differentiator is its seamless integration with the Fumadocs MDX processing pipeline, allowing for automatic type generation and validation of content-level metadata, crucial for large-scale documentation sites. This significantly enhances the developer experience by providing autocompletion and compile-time checks for content properties.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure `fumadocs-typescript` within your `next.config.mjs` file. It shows defining a frontmatter schema, initializing the `createLoader`, and chaining it with `@fumadocs/mdx` for content processing to enable type-safe frontmatter.

// next.config.mjs
import { createLoader } from 'fumadocs-typescript/loader';
import { createMDX } from '@fumadocs/mdx'; // A common companion package in Fumadocs projects

// Define your frontmatter schema here. This schema will be used by
// fumadocs-typescript to generate corresponding TypeScript types for your MDX content.
const myFrontmatterSchema = {
  title: { type: 'string', required: true, description: 'The title of the document' },
  description: { type: 'string', optional: true, description: 'A brief summary of the content' },
  date: { type: 'string', optional: true, format: 'date', description: 'Publication date (YYYY-MM-DD)' },
  tags: { type: 'array', items: { type: 'string' }, optional: true, description: 'Categorization tags' },
  category: { type: 'enum', enum: ['guides', 'api', 'tutorials'], optional: true, description: 'Content category' }
};

// Initialize the Fumadocs TypeScript loader with your schema.
// This loader processes the schema to generate a `types.d.ts` file,
// enabling type-safe access to frontmatter in your components.
const withFumadocsTypescript = createLoader({
  schema: myFrontmatterSchema,
  // By default, types are generated in .fumadocs/types.d.ts. You can customize the output path:
  // outputPath: './custom-types/my-fumadocs-types.d.ts',
});

// Integrate with the main Fumadocs MDX loader for content processing.
// This is a typical setup in Fumadocs projects, chaining the loaders.
const withFumadocsMDX = createMDX({
  content: {
    // Configure where your MDX content is located, e.g., all files under the 'content' directory
    root: 'content',
  },
});

/** @type {import('next').NextConfig} */
const nextConfig = {
  // Your standard Next.js configuration options go here
  reactStrictMode: true,
  // Add any other Next.js specific configurations
};

// Chain the loaders: the TypeScript loader typically runs 'before' or in conjunction
// with the MDX loader to ensure types are available for content processing.
export default withFumadocsMDX(withFumadocsTypescript(nextConfig));

// --- Example MDX file (content/getting-started.mdx) ---
// ---
// title: Getting Started with Fumadocs
// description: Learn how to set up your first Fumadocs project with TypeScript.
// date: 2023-10-26
// tags: ["guide", "setup", "typescript"]
// category: "guides"
// ---

// # Hello Fumadocs!

// This is your first document using type-safe frontmatter.
// Access `frontmatter.title` in your React components with full TypeScript support.

view raw JSON →