Warning
This is an internal project, and is not intended for public use. No support or stability guarantees are provided.
A server-side function for loading and processing TypeScript types with syntax highlighting. This function coordinates the type extraction pipeline and applies HAST transformations for rendering.
loadServerTypes is the primary server-side entry point for type documentation processing. It:
syncTypes to extract and format TypeScript types (plain text)highlightTypes to highlight markdown code blocks in descriptions/examplesenhanceCodeTypes to convert type strings to syntax-highlighted HASTThis three-stage pipeline separates concerns:
import { loadServerTypes } from '@mui/internal-docs-infra/pipeline/loadServerTypes';
// Load and process types with highlighting
const result = await loadServerTypes({
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.exports); // Record<string, ExportData> with enhanced types
console.log(result.additionalTypes); // EnhancedTypesMeta[] for top-level types
console.log(result.allDependencies); // string[] - files to watch
const result = await loadServerTypes({
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
performanceLogging: true,
});
LoadServerTypesOptions extends SyncTypesOptions:
interface LoadServerTypesOptions extends SyncTypesOptions {}
interface 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;
}
interface LoadServerTypesResult {
/** Export data where each export has a main type and related additional types */
exports: Record<string, ExportData>;
/** Top-level non-namespaced types like InputType */
additionalTypes: EnhancedTypesMeta[];
/**
* 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[]>;
/** All dependencies that should be watched for changes */
allDependencies: string[];
/** Type name map from variant processing */
typeNameMap?: Record<string, string>;
/**
* Map from type names to anchor hrefs for linking type references in code.
* Keys include both dotted names ("Accordion.Trigger") and flat names ("AccordionTrigger").
*/
anchorMap: Record<string, string>;
}
Note:
exportsandadditionalTypescontainEnhancedTypesMetawith HAST fields (type,shortType,detailedType,default) ready for rendering.
Delegates to syncTypes for core type processing:
types.md with the latest documentationTransforms markdown content with syntax highlighting:
const highlightResult = await highlightTypes(syncResult.variantData);
The highlightTypes function processes:
It also builds a highlightedExports map that maps export names to their highlighted type definitions for expansion in the next stage.
Note: Type strings (
typeText,defaultText) remain as plain text at this stage.
Converts plain text type fields to syntax-highlighted HAST:
const enhancedVariantData = await enhanceCodeTypes(highlightResult.variantData, {
highlightedExports: highlightResult.highlightedExports,
formatting: formattingOptions,
});
The enhanceCodeTypes function:
typeText → type (syntax-highlighted HAST)shortType from the highlighted type structure (e.g., "Union", "function")detailedType with expanded type references (when needed)defaultText → default (syntax-highlighted HAST)loadServerTypes when:EnhancedTypesMeta with HAST fields ready for renderingsyncTypes directly when:typeText)types.md fileThe function inherits performance characteristics from syncTypes:
~500-1200ms to create TypeScript program and parse types
~100-140ms using cached program and file data
highlightTypes: Typically adds 10-50ms for markdown code block highlightingenhanceCodeTypes: Typically adds 5-20ms for type string → HAST conversionsyncTypes - Core type synchronization (called internally)loadPrecomputedTypes - Webpack loader that uses this functionabstractCreateTypes - Create type documentation factoriesServer-side function for loading and processing TypeScript types.
This function:
The pipeline is:
| Parameter | Type | Description |
|---|---|---|
| options | { sync?: boolean; typesMarkdownPath: string; rootContext: string; variants?: Record<string, string>; watchSourceDirectly?: boolean; formattingOptions?: FormatInlineTypeOptions; socketDir?: string; performanceLogging?: boolean; updateParentIndex?: { baseDir?: string; onlyUpdateIndexes?: boolean; markerDir?: string; errorIfOutOfDate?: boolean; indexFileName?: string }; externalTypesPattern?: string } |
Promise<LoadServerTypesResult>type EnhancedClassProperty = {
isStatic?: boolean;
readonly?: boolean;
type: Root;
shortType?: Root;
shortTypeText?: string;
default?: Root;
detailedType?: Root;
typeText: string;
defaultText?: string;
required?: true;
description?: Root;
descriptionText?: string;
example?: Root;
exampleText?: string;
see?: Root;
seeText?: string;
};type EnhancedClassTypeMeta = {
constructorParameters: Record<string, EnhancedParameter>;
properties: Record<string, EnhancedClassProperty>;
methods: Record<string, EnhancedMethod>;
name: string;
description?: HastRoot;
descriptionText?: string;
typeParameters?: string[];
};type EnhancedComponentTypeMeta = {
props: Record<string, EnhancedProperty>;
name: string;
description?: HastRoot;
descriptionText?: string;
dataAttributes: Record<string, FormattedEnumMember>;
cssVariables: Record<string, FormattedEnumMember>;
};type EnhancedEnumMemberMeta = {
description?: Root;
name: string;
descriptionText?: string;
value?: string | number;
};type EnhancedFunctionTypeMeta = {
parameters: Record<string, EnhancedParameter>;
returnValue: Record<string, EnhancedProperty> | Root;
name: string;
description?: HastRoot;
descriptionText?: string;
returnValueText?: string;
returnValueDescription?: HastRoot;
returnValueDescriptionText?: string;
};type EnhancedHookTypeMeta = {
parameters: Record<string, EnhancedParameter | EnhancedProperty>;
returnValue: Record<string, EnhancedProperty> | Root;
name: string;
description?: HastRoot;
descriptionText?: string;
returnValueText?: string;
returnValueDescription?: HastRoot;
returnValueDescriptionText?: string;
};type EnhancedMethod = {
parameters: Record<string, EnhancedParameter>;
returnValue: Root;
returnValueDescription?: Root;
name: string;
description?: HastRoot;
descriptionText?: string;
returnValueDescriptionText?: string;
isStatic: boolean;
};type EnhancedParameter = {
type: Root;
shortType?: Root;
shortTypeText?: string;
default?: Root;
detailedType?: Root;
typeText: string;
defaultText?: string;
optional?: true;
description?: Root;
descriptionText?: string;
example?: Root;
exampleText?: string;
see?: Root;
seeText?: string;
};type EnhancedProperty = {
type: Root;
shortType?: Root;
shortTypeText?: string;
default?: Root;
detailedType?: Root;
typeText: string;
defaultText?: string;
required?: true;
description?: Root;
descriptionText?: string;
example?: Root;
exampleText?: string;
see?: Root;
seeText?: string;
};type EnhancedRawTypeMeta = {
description?: Root;
formattedCode: Root;
enumMembers?: EnhancedEnumMemberMeta[];
name: string;
descriptionText?: string;
reExportOf?: ReExportInfo;
dataAttributesOf?: string;
cssVarsOf?: string;
};type EnhancedTypesMeta =
| { type: 'component'; name: string; slug?: string; data: EnhancedComponentTypeMeta }
| { type: 'hook'; name: string; slug?: string; data: EnhancedHookTypeMeta }
| { type: 'function'; name: string; slug?: string; data: EnhancedFunctionTypeMeta }
| { type: 'class'; name: string; slug?: string; data: EnhancedClassTypeMeta }
| { type: 'raw'; name: string; slug?: string; data: EnhancedRawTypeMeta };type LoadServerTypesOptions = {
sync?: boolean;
typesMarkdownPath: string;
rootContext: string;
variants?: Record<string, string>;
watchSourceDirectly?: boolean;
formattingOptions?: FormatInlineTypeOptions;
socketDir?: string;
performanceLogging?: boolean;
updateParentIndex?: {
baseDir?: string;
onlyUpdateIndexes?: boolean;
markerDir?: string;
errorIfOutOfDate?: boolean;
indexFileName?: string;
};
externalTypesPattern?: string;
};type LoadServerTypesResult = {
exports: Record<string, ExportData>;
additionalTypes: EnhancedTypesMeta[];
variantTypeNames: Record<string, string[]>;
allDependencies: string[];
typeNameMap?: Record<string, string>;
anchorMap: Record<string, string>;
};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 };