Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The core server-side function for loading and formatting TypeScript type metadata. This function extracts types from your source files and returns formatted data ready for documentation generation or rendering.
loadServerTypesMeta handles the TypeScript → formatted types pipeline:
This function is separated from syncTypes to allow direct access to formatted types without markdown generation. Use this when you need type metadata but don't need to write a types.md file.
Note: Type highlighting is handled separately by
loadServerTypes, which callssyncTypes(which uses this function) and then applieshighlightTypesandhighlightTypesMetato convert plain text types to syntax-highlighted HAST.
import { loadServerTypesMeta } from '@mui/internal-docs-infra/pipeline/loadServerTypesMeta';
// Load and format types (no file writing)
const result = await loadServerTypesMeta({
typesMarkdownPath: '/absolute/path/to/types.md',
rootContext: '/absolute/path/to/project',
variants: { Default: '@base-ui/react/checkbox' },
formattingOptions: {
shortTypeUnionPrintWidth: 40,
defaultValueUnionPrintWidth: 40,
},
});
// Use the results
console.log(result.allTypes); // TypesMeta[] - all formatted types
console.log(result.variantData); // Record<string, { types: TypesMeta[]; typeNameMap?: Record<string, string> }>
console.log(result.allDependencies); // string[] - files to watch
console.log(result.externalTypes); // Record<string, string> - external type definitions
console.log(result.resourceName); // string - derived name for display
const result = await loadServerTypesMeta({
typesMarkdownPath: '/absolute/path/to/types.md',
rootContext: '/absolute/path/to/project',
variants: { Default: '@base-ui/react/checkbox' },
socketDir: '/tmp/my-custom-socket-dir', // For Windows compatibility
});
const result = await loadServerTypesMeta({
typesMarkdownPath: '/absolute/path/to/types.md',
rootContext: '/absolute/path/to/project',
variants: { Default: '@base-ui/react/checkbox' },
// Only include specific external types
externalTypesPattern: '^(Orientation|Alignment|Side)$',
});
Loads and caches tsconfig.json from the root context:
const config = await loadTypescriptConfig(path.join(rootContext, 'tsconfig.json'));
Resolves variant paths through tsconfig paths, handling:
@base-ui/react/*)Automatically discovers DataAttributes.ts and CssVars.ts files from:
../menu/)const metaFiles = await findMetaFiles(componentDirectory);
// Returns: ['CheckboxDataAttributes.ts', 'CheckboxCssVars.ts']
Sends type extraction work to a dedicated worker thread:
const workerResult = await workerManager.processTypes({
projectPath: config.projectPath,
compilerOptions: config.options,
allEntrypoints,
metaFiles,
resolvedVariantMap,
dependencies: config.dependencies,
rootContextDir,
relativePath,
});
Converts raw TypeScript exports to formatted structures based on type:
formatComponentData - extracts props, data attributes, CSS variablesformatHookData - extracts parameters, return valueformatFunctionData - extracts parameters, return valueformatClassData - extracts properties, methodsformatRawData - formats type declarationFor single-variant exports with sub-components (e.g., Accordion.Root, Accordion.Trigger), groups types by component:
// Before: { Default: { types: [Accordion.Root, Accordion.Trigger, ...] } }
// After: { "Accordion.Root": { types: [...] }, "Accordion.Trigger": { types: [...] } }
Identifies when type exports (like ButtonProps) are just re-exports of component props:
// ButtonProps → marks as re-export of Button#props
// CheckboxDataAttributes → marks as re-export of Checkbox#data-attributes
Gathers types referenced in props/params that aren't publicly exported:
// e.g., Orientation = 'horizontal' | 'vertical'
// These are collected and returned in externalTypes
The function uses a worker-based architecture for efficient TypeScript processing:
typescript-api-extractorFor multi-process environments (Next.js with multiple workers):
~500-1200ms to create TypeScript program and parse types
~100-140ms using cached program and file data
87-92% performance improvement vs. creating separate language services per process
| Function | Purpose | Writes Files | Returns |
|---|---|---|---|
loadServerTypesMeta | Load & format types | ❌ | Plain text types |
syncTypes | Sync types.md file | ✅ types.md | Plain text types + exports structure |
loadServerTypes | Full pipeline with highlighting | ✅ types.md | HAST-highlighted types |
loadServerTypesMetaLoads and formats TypeScript types from source files.
This function handles:
The result can be used by syncTypes for markdown generation or by other consumers.
| Parameter | Type | Description |
|---|---|---|
| options | { typesMarkdownPath: string; rootContext: string; variants?: Record<string, string>; watchSourceDirectly?: boolean; formattingOptions?: FormatInlineTypeOptions; socketDir?: string; externalTypesPattern?: string } |
Promise<LoadServerTypesMetaResult>prettyFormat| Parameter | Type | Description |
|---|---|---|
| type | string | |
| typeName | string | null | undefined | |
| printWidth | number | undefined |
Promise<string>prettyFormatMarkdownFormats a markdown string with Prettier’s markdown parser. Used for non-code sections of generated markdown to ensure consistent formatting.
| Parameter | Type | Description |
|---|---|---|
| markdown | string | The markdown string to format |
| printWidth | number | undefined | Optional maximum line width for Prettier formatting (default: 100) |
Promise<string>The formatted markdown string
Formatted property metadata for class properties.
type ClassFormattedProperty = {
name: string;
typeText: string;
description?: HastRoot;
descriptionText?: string;
optional: boolean;
readonly: boolean;
isStatic: boolean;
};type ClassTypeMeta = {
name: string;
description?: HastRoot;
descriptionText?: string;
constructorParameters: Record<string, FormattedParameter>;
properties: Record<string, FormattedProperty>;
methods: Record<string, FormattedMethod>;
typeParameters?: string[];
};type ComponentTypeMeta = {
name: string;
description?: HastRoot;
descriptionText?: string;
props: Record<string, FormattedProperty>;
dataAttributes: Record<string, FormattedEnumMember>;
cssVariables: Record<string, FormattedEnumMember>;
};Enum member metadata for raw type enum rendering.
type EnumMemberMeta = {
name: string;
value?: string | number;
description?: HastRoot;
descriptionText?: string;
};Options for formatting inline types as HAST.
type FormatInlineTypeOptions = {
shortTypeUnionPrintWidth?: number;
defaultValueUnionPrintWidth?: number;
detailedTypePrintWidth?: number;
};type FormattedEnumMember = { description?: Root; descriptionText?: string; type?: string };Formatted method metadata for class methods.
type FormattedMethod = {
name: string;
description?: HastRoot;
descriptionText?: string;
parameters: Record<string, FormattedParameter>;
returnValue: string;
returnValueDescription?: HastRoot;
returnValueDescriptionText?: string;
isStatic: boolean;
};type FormattedParameter = {
typeText: string;
defaultText?: string;
optional?: true;
description?: Root;
descriptionText?: string;
example?: Root;
exampleText?: string;
see?: Root;
seeText?: string;
};type FormattedProperty = {
typeText: string;
defaultText?: string;
required?: true;
description?: Root;
descriptionText?: string;
example?: Root;
exampleText?: string;
see?: Root;
seeText?: string;
};type FunctionTypeMeta = {
name: string;
description?: HastRoot;
descriptionText?: string;
parameters: Record<string, FormattedParameter>;
returnValue: Record<string, FormattedProperty> | string;
returnValueText?: string;
returnValueDescription?: HastRoot;
returnValueDescriptionText?: string;
};type HookTypeMeta = {
name: string;
description?: HastRoot;
descriptionText?: string;
parameters: Record<string, FormattedParameter | FormattedProperty>;
returnValue: Record<string, FormattedProperty> | string;
returnValueText?: string;
returnValueDescription?: HastRoot;
returnValueDescriptionText?: string;
};type LoadServerTypesMetaOptions = {
typesMarkdownPath: string;
rootContext: string;
variants?: Record<string, string>;
watchSourceDirectly?: boolean;
formattingOptions?: FormatInlineTypeOptions;
socketDir?: string;
externalTypesPattern?: string;
};type LoadServerTypesMetaResult = {
allDependencies: string[];
typeNameMap?: Record<string, string>;
externalTypes: Record<string, string>;
resourceName: string;
exports: Record<string, { type: TypesMeta; additionalTypes: TypesMeta[] }>;
additionalTypes: TypesMeta[];
variantTypeNames: Record<string, string[]>;
variantTypeNameMaps: Record<string, Record<string, string>>;
};type namespaceParts = string[];type RawTypeMeta = {
name: string;
description?: HastRoot;
descriptionText?: string;
formattedCode: string;
enumMembers?: EnumMemberMeta[];
reExportOf?: ReExportInfo;
dataAttributesOf?: string;
cssVarsOf?: string;
};type ReExportInfo = {
name: string;
slug: string;
suffix: 'props' | 'css-variables' | 'data-attributes';
};type TypesMeta =
| { type: 'class'; name: string; slug?: string; data: ClassTypeMeta }
| { type: 'component'; name: string; slug?: string; data: ComponentTypeMeta }
| { type: 'hook'; name: string; slug?: string; data: HookTypeMeta }
| { type: 'function'; name: string; slug?: string; data: FunctionTypeMeta }
| { type: 'raw'; name: string; slug?: string; data: RawTypeMeta };type typeSuffixes = string[];loadServerTypes - Full pipeline with highlightingloadPrecomputedTypes - Webpack loader that uses syncTypestypescript-api-extractor - Underlying type extraction library