Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
The server-side function for synchronizing TypeScript type documentation to disk. This function coordinates type loading and markdown generation, updating the types.md file and optionally the parent index page.
syncTypes is the orchestration function that:
loadServerTypesMeta to load and format TypeScript typesgenerateTypesMarkdowntypes.md with the latest type documentationThis function is separated from the webpack loader to allow reuse in other contexts (e.g., API routes, scripts, or custom build tools).
Note: Type highlighting is handled separately by
loadServerTypes, which calls this function and then applieshighlightTypesandhighlightTypesMetato convert plain text types to syntax-highlighted HAST.
import { syncTypes } from '@mui/internal-docs-infra/pipeline/syncTypes';
// Sync the types (updates types.md and returns latest data)
const result = await syncTypes({
typesMarkdownPath: '/absolute/path/to/types.md',
rootContext: '/absolute/path/to/project',
variants: { Default: '@base-ui/react/checkbox' },
// Optional: watchSourceDirectly
formattingOptions: {
shortTypeUnionPrintWidth: 40,
defaultValueUnionPrintWidth: 40,
},
// Optional: transform extracted descriptions
descriptionReplacements: [{ pattern: '\\n\\nDocumentation:.*$', replacement: '', flags: 'm' }],
});
// Use the results
console.log(result.exports); // Record<string, { type: TypesMeta; additionalTypes: TypesMeta[] }>
console.log(result.additionalTypes); // TypesMeta[] for top-level types
console.log(result.variantOnlyAdditionalTypes); // Record<string, TypesMeta[]> for types-only module variants
console.log(result.allDependencies); // string[] - files to watch
The return type is TypesSourceData, the shared contract consumed by loadServerTypes. See the loadServerTypes overview for details on this shared structure.
Note: The result contains plain text type fields (
typeText,defaultText). UseloadServerTypesif you needHighlightedTypesMetawith syntax-highlighted HAST fields (type,shortType,detailedType,default).
For details on the TypesMeta union type and its variants (component, hook, function, class, raw), see loadServerTypesMeta.
syncTypes coordinates a two-stage pipeline:
Delegates to loadServerTypesMeta:
const typesMetaResult = await loadServerTypesMeta({
typesMarkdownPath,
rootContext,
variants,
watchSourceDirectly,
formattingOptions,
socketDir,
externalTypesPattern,
});
This handles TypeScript configuration, worker processing, and type formatting. See loadServerTypesMeta Processing Pipeline for details.
Generates markdown documentation and writes to disk:
const markdown = await generateTypesMarkdown({
name: resourceName,
organized: {
exports,
additionalTypes,
variantOnlyAdditionalTypes,
variantTypeNames,
variantTypeNameMaps,
},
typeNameMap,
externalTypes,
path: relativePath,
});
// Only write if changed
const existingMarkdown = await readFile(typesMarkdownPath, 'utf-8').catch(() => null);
if (existingMarkdown !== markdown) {
await writeFile(typesMarkdownPath, markdown, 'utf-8');
}
When updateParentIndex is configured, updates the parent directory's index page:
await syncPageIndex({
pagePath,
metadata: pageMetadata, // props, dataAttributes, cssVariables, parameters
baseDir: updateParentIndex.baseDir,
indexFileName: updateParentIndex.indexFileName,
// ...
});
Deep dive: For details on the TypeScript processing pipeline (configuration loading, worker architecture, type formatting), see
loadServerTypesMeta.
loadServerTypesMeta - Core type loading and formatting (used internally)loadServerTypes - Server-side function that calls this and applies highlightingloadPrecomputedTypes - Webpack loader that uses this functionsyncPageIndex - Updates parent index pages with component metadataabstractCreateTypes - Create type documentation factoriestypescript-api-extractor - Underlying type extraction librarySyncs types for a component/hook/function.
This is separated from the webpack loader to allow reuse in other contexts.
| Property | Type | Description |
|---|---|---|
| typesMarkdownPath | | Absolute path to the types.md file to generate |
| rootContext | | Root context directory (workspace root) |
| variants | | Map of variant name to file path (relative or package path).
For single component: |
| watchSourceDirectly | | When true, resolves library paths to their source files for watching. Useful during development to watch the original source rather than built files. |
| formattingOptions | | Options for formatting types in tables |
| socketDir | | Directory path for socket and lock files used for IPC between workers. Useful for Windows where the default temp directory may not support Unix domain sockets. |
| performanceLogging | | Enable performance logging |
| updateParentIndex | | Options for updating the parent index page with component metadata. When provided, will call syncPageIndex to update the parent directory’s page.mdx with props, dataAttributes, and cssVariables extracted from the component types. These options are passed through to syncPageIndex. |
| externalTypesPattern | | Optional regex pattern string to filter which external types to include.
External types are named union types (like When not provided, ALL qualifying named union types (unions of literals) will be collected automatically. This is the recommended behavior for most projects. When provided, only external types whose names match this pattern will be collected. |
| ordering | | Custom ordering configuration for sorting props, data attributes, exports, etc. |
| descriptionReplacements | | Pattern/replacement pairs to apply to JSDoc descriptions.
Each entry has a |
Promise<TypesSourceData>type SyncTypesOptions = {
/** Absolute path to the types.md file to generate */
typesMarkdownPath: string;
/** Root context directory (workspace root) */
rootContext: string;
/**
* Map of variant name to file path (relative or package path).
* For single component: `{ Default: './Component' }`
* For multiple: `{ CssModules: './css-modules/Component', Tailwind: './tailwind/Component' }`
*/
variants?: Record<string, string>;
/**
* When true, resolves library paths to their source files for watching.
* Useful during development to watch the original source rather than built files.
*/
watchSourceDirectly?: boolean;
/** Options for formatting types in tables */
formattingOptions?: FormatInlineTypeOptions;
/**
* Directory path for socket and lock files used for IPC between workers.
* Useful for Windows where the default temp directory may not support Unix domain sockets.
*/
socketDir?: string;
/** Enable performance logging */
performanceLogging?: boolean;
/**
* Options for updating the parent index page with component metadata.
* When provided, will call syncPageIndex to update the parent directory's page.mdx
* with props, dataAttributes, and cssVariables extracted from the component types.
*
* These options are passed through to syncPageIndex.
*/
updateParentIndex?: {
baseDir?: string;
onlyUpdateIndexes?: boolean;
markerDir?: string;
errorIfOutOfDate?: boolean;
indexFileName?: string;
};
/**
* Optional regex pattern string to filter which external types to include.
* External types are named union types (like `Orientation = 'horizontal' | 'vertical'`)
* that are referenced in props but not exported from the component's module.
*
* When not provided, ALL qualifying named union types (unions of literals) will be
* collected automatically. This is the recommended behavior for most projects.
*
* When provided, only external types whose names match this pattern will be collected.
* @example undefined // Collect all qualifying external types (recommended)
* @example '^(Orientation|Alignment|Side)$' // Only include specific types
*/
externalTypesPattern?: string;
/** Custom ordering configuration for sorting props, data attributes, exports, etc. */
ordering?: OrderingConfig;
/**
* Pattern/replacement pairs to apply to JSDoc descriptions.
* Each entry has a `pattern` (regex string) and `replacement` string.
*/
descriptionReplacements?: DescriptionReplacement[];
}