MUI Docs Infra

Warning

This is an internal project, and is not intended for public use. No support or stability guarantees are provided.

Load Server Types Text

A function for parsing types.md files back into structured type metadata. This is the reverse operation of syncTypes — it reads markdown and reconstructs organized type exports.

Overview

loadServerTypesText parses a types.md file that was previously generated by syncTypes. It reconstructs:

  • Component, hook, function, and raw type metadata
  • Props, parameters, properties, data attributes, CSS variables, and return value tables
  • Prop/parameter examples and references
  • External types section
  • Variant metadata (Export Groups and Canonical Types sections)

Both loadServerTypesText and loadServerTypesMeta extend OrganizeTypesResult<TypesMeta> and share the same core fields (exports, additionalTypes, externalTypes, typeNameMap, allDependencies). This shared shape (TypesSourceData) is the contract consumed by loadServerTypes, which accepts either function's output and applies highlighting on top.

This is useful for:

  • Reading pre-generated documentation without re-running TypeScript analysis
  • Testing and debugging the type generation pipeline
  • Building tools that consume type documentation

Usage

import { loadServerTypesText } from '@mui/internal-docs-infra/pipeline/loadServerTypesText';

// Load types from a file URL
const result = await loadServerTypesText('file:///absolute/path/to/types.md');

// Access the parsed types
result.exports; // Record<string, { type: TypesMeta; additionalTypes: TypesMeta[] }>
result.additionalTypes; // TypesMeta[] — top-level non-namespaced types
result.externalTypes; // Record<string, string> — external type definitions
result.variantTypeNames; // Record<string, string[]> — variant → type names
result.typeNameMap; // Record<string, string> — flat name → dotted name
result.allDependencies; // string[] — file paths to watch

Markdown Format

The parser expects markdown in the format generated by syncTypes:

Type Sections

Each type is defined by an H3 heading (###) followed by optional description and tables:

### ComponentName

Optional description paragraph.

**ComponentName Props:**

| Prop       | Type      | Default     | Description                    |
| ---------- | --------- | ----------- | ------------------------------ |
| propName   | `string`  | `"default"` | Prop description               |
| required\* | `boolean` | -           | Required prop (marked with \*) |

Type Detection

The parser determines type kind based on content:

  1. Re-export: If the type is a re-export → raw
  2. Hook: Name starts with usehook
  3. Component: Has props, data attributes, or CSS variables → component
  4. Function: Has parameters, properties, or return value → function
  5. Raw: Has a code block definition → raw
  6. Default: Falls back to component

Tables

The parser recognizes these table formats, identified by bold headings like **Name Props:**:

  • Props: | Prop | Type | Default | Description | (4 columns)
  • Parameters: | Parameter | Type | Default | Description | (4 columns)
  • Properties: Parsed like Props (4 columns) — for hooks/functions with a single anonymous object parameter
  • Data Attributes: | Attribute | Type | Description | (3 columns)
  • CSS Variables: | Variable | Type | Description | (3 columns)
  • Return Value: | Property | Type | Description | (3 columns), or a code block

Additionally, the parser recognizes:

  • Prop/Parameter Examples: Bold headings like **`propName` Prop Example:** followed by a code block
  • Prop/Parameter References: Bold headings like **`propName` Prop References:** followed by a bullet list

External Types

External types are parsed from the ## External Types H2 section. Each type uses an H4 heading (####) with a code block:

## External Types

#### TypeName

\`\`\`typescript
type TypeName = string | number;
\`\`\`

Embedded Metadata

Variant and type name mapping metadata is stored in dedicated H2 sections:

Export Groups lists which types belong to each variant:

## Export Groups

- `Default`: `Button`, `ButtonProps`
- `Shared`

Canonical Types maps flat names to canonical dotted names, optionally scoped to variants:

## Canonical Types

- `Accordion.Trigger` (`Default`): `AccordionTrigger`
- `Accordion.Root`: `AccordionRoot`

Types

Load and parse a types.md file into TypesMeta[].

ParameterTypeDescription
fileUrl
string

file:// URL to the types.md file

ordering
OrderingConfig | undefined
Return Type

Parsed types and external types

TypesSourceData

Common data returned by both syncTypes and loadServerTypesText. This is the shared contract consumed by loadServerTypes.

type TypesSourceData = {
  /** External types discovered in the file */
  externalTypes: Record<string, string>;
  /**
   * Type name map (merged across all variants).
   * Maps flat names (like "AccordionTriggerState") to dotted names (like "Accordion.Trigger.State").
   */
  typeNameMap: Record<string, string>;
  /** All dependencies that should be watched for changes */
  allDependencies: string[];
  /** Whether the types.md file was updated (false if loaded from existing file) */
  updated: boolean;
  /** Export data where each export has a main type and related additional types */
  exports: Record<string, { type: TypesMeta; additionalTypes: TypesMeta[] }>;
  /** Top-level non-namespaced types not claimed by any variant-only group */
  additionalTypes: TypesMeta[];
  /**
   * Types belonging to variant-only groups (variants with no main export).
   * Keyed by variant name, each entry contains the types from that variant.
   * These are separated from `additionalTypes` to avoid duplication.
   */
  variantOnlyAdditionalTypes: Record<string, TypesMeta[]>;
  /**
   * Maps variant names to the type names that originated from that variant.
   * Used for namespace imports (e.g., `* as Types`) to filter additionalTypes
   * to only show types from that specific module.
   */
  variantTypeNames: Record<string, string[]>;
  /**
   * Maps variant names to their per-variant typeNameMaps.
   * Used for Canonical Types annotations showing which variants contain each type.
   */
  variantTypeNameMaps: Record<string, Record<string, string>>;
}
  • syncTypes - Generates the types.md files that this function parses
  • loadServerTypes - Calls this function (when sync: false) or syncTypes, then applies highlighting