Skip to main content

Overview

The TypeInfo generation system converts Microsoft API Extractor’s API model into a structured JSON format compatible with Mintlify’s <TypeTree open> component. The key challenge is fully recursive type expansion - extracting not just top-level properties, but all nested object structures with their complete documentation.

Architecture

Core Components

The TypeInfo generation pipeline consists of:

TypeInfoGenerator (src/utils/TypeInfoGenerator.ts)

The main orchestrator responsible for:
  • Loading API models from API Extractor output
  • Recursively processing API items (interfaces, classes, type aliases)
  • Resolving type references across the API model
  • Converting to TypeTreeProperty-compatible format
  • Generating both .jsx and .d.ts files

ObjectTypeAnalyzer (src/utils/ObjectTypeAnalyzer.ts)

Utility for parsing complex TypeScript type strings:
  • Parses inline object type literals
  • Extracts nested properties, unions, intersections
  • Handles generics and array types
  • Returns structured TypeAnalysis objects

CacheManager (src/cache/)

Performance optimization layer:
  • Caches parsed type strings (TypeAnalysisCache)
  • Caches API item lookups (ApiResolutionCache)
  • LRU eviction for memory management

The Recursive Type Resolution Algorithm

Problem Statement

Given a TypeScript interface like:
We need to generate TypeInfo with fully nested documentation:

Core Algorithm

The resolution happens in _extractNestedProperties():

Why Named Interfaces Are Critical

API Extractor Limitation: JSDoc comments are not preserved for properties within inline object type literals. Only named interfaces preserve full documentation.
Bad (loses documentation):
Good (preserves documentation):
The algorithm handles both cases:
  1. Named references: Looks up in API model → gets full docs recursively
  2. Inline objects: Parses structure only → no property-level docs

Key Methods

_processProperty()

Converts an API Extractor property item to TypeInfo format:

_findApiItemByName()

Critical for type reference resolution:
Limitation: Currently only searches entry point members. Doesn’t handle:
  • Nested namespace members
  • Re-exported types from external packages
  • Types in different entry points

_convertTypeAnalysisToString()

Converts parsed type structures back to readable type strings:

Output Generation

TypeInfo.jsx

JavaScript module with the complete type structure:

TypeInfo.d.ts

TypeScript declaration for IDE autocomplete:

Performance Considerations

Caching Strategy

The system uses two-level caching:
  1. Type Analysis Cache (ObjectTypeAnalyzer)
    • Caches parsed type strings
    • Key: raw type string
    • Value: TypeAnalysis object
    • Prevents redundant parsing of common types
  2. API Resolution Cache (Future optimization)
    • Could cache _findApiItemByName() lookups
    • Currently uses JSON.stringify() for keys (slow)
    • Opportunity for improvement with better key generation

Recursion Depth

The recursive algorithm naturally terminates because:
  1. TypeScript doesn’t allow circular type references at the value level
  2. Each recursion processes a unique API item
  3. Primitive types (string, number, etc.) end the recursion
No explicit depth limit is needed, though one could be added for safety.

Integration Points

MarkdownDocumenter

The TypeInfoGenerator is called from MarkdownDocumenter._writeApiItemPage():

Configuration

TypeInfo generation is always enabled and runs automatically during mint-tsdocs generate. There are currently no configuration options to disable or customize it.

Known Limitations

1. Entry Point Scope

_findApiItemByName() only searches the first entry point of each package. This means: Won’t resolve:
  • Types in nested namespaces
  • Re-exported types from external packages
  • Types in additional entry points
Will resolve:
  • Top-level interfaces, classes, type aliases
  • Types in the same package as the referencing property

2. Inline Object Types

Properties within inline object type literals don’t have descriptions:
Solution: Always use named interfaces for types that need documentation.

3. Complex Type References

Advanced TypeScript features may not be fully resolved:
  • Conditional types
  • Mapped types
  • Template literal types
  • Utility types (Partial, Pick, etc.)
These will show the raw type string without expansion.

Future Improvements

1. Enhanced Type Resolution

  • Support for nested namespace members
  • Cross-package type resolution
  • Handling of re-exported types

2. Smarter Caching

  • Replace JSON.stringify() in API resolution cache
  • Implement TTL for cache entries
  • Statistics for cache hit rates

3. Configuration Options

  • Option to disable TypeInfo generation
  • Control over recursion depth
  • Custom type transformers

4. Error Handling

  • Better diagnostics when type resolution fails
  • Warnings for unresolved type references
  • Validation of generated TypeInfo structure

Testing

TypeInfo generation is tested through:
  1. Snapshot tests: Verify output structure remains consistent
  2. Integration tests: Run full generation pipeline on test projects
  3. Manual verification: Check generated files in actual documentation
To test TypeInfo generation:

References