콘텐츠로 이동

TypeDoc Cheat Sheet

Overview

TypeDoc is a documentation generator specifically designed for TypeScript and JavaScript projects. It reads TypeScript source files, extracts type information from the compiler, and combines it with JSDoc-style comments to produce comprehensive API documentation. Output formats include static HTML sites and JSON data that can be consumed by other tools.

TypeDoc understands the full TypeScript type system including generics, union types, interfaces, enums, and decorators. It supports plugins for custom output formats, themes for visual customization, and can document both library APIs and application code.

Installation

# Install as a dev dependency
npm install --save-dev typedoc

# Install globally
npm install -g typedoc

# Install with plugin support
npm install --save-dev typedoc typedoc-plugin-markdown

# Verify installation
npx typedoc --version

Quick Start

# Generate docs from a single entry point
npx typedoc src/index.ts

# Specify output directory
npx typedoc --out docs src/index.ts

# Generate JSON output
npx typedoc --json docs/api.json src/index.ts

# Watch mode for development
npx typedoc --watch

Configuration

typedoc.json

{
  "$schema": "https://typedoc.org/schema.json",
  "entryPoints": ["src/index.ts"],
  "out": "docs",
  "name": "My Library API",
  "readme": "README.md",
  "includeVersion": true,
  "excludePrivate": true,
  "excludeProtected": false,
  "excludeInternal": true,
  "excludeExternals": true,
  "theme": "default",
  "categorizeByGroup": true,
  "categoryOrder": ["Core", "Utilities", "Types", "*"],
  "navigation": {
    "includeCategories": true,
    "includeGroups": true
  },
  "plugin": ["typedoc-plugin-markdown"],
  "sort": ["source-order"],
  "hideGenerator": true,
  "searchInComments": true
}

CLI Options

OptionDescription
--entryPoints <files>Entry point source files
--out <dir>Output directory
--json <file>Output JSON instead of HTML
--tsconfig <file>Path to tsconfig.json
--readme <file>README file to include
--name <name>Project name in docs
--theme <name>Documentation theme
--exclude <patterns>Glob patterns to exclude
--excludePrivateExclude private members
--excludeProtectedExclude protected members
--excludeInternalExclude @internal tagged items
--plugin <plugins>Load plugins
--watchWatch for file changes
--emit docOnly emit documentation
--sort <strategy>Sort order for members

Comment Syntax

TSDoc / JSDoc Tags

/**
 * Calculates the distance between two points in 2D space.
 *
 * @remarks
 * Uses the Euclidean distance formula.
 *
 * @example
 * ```ts
 * const d = distance({ x: 0, y: 0 }, { x: 3, y: 4 });
 * console.log(d); // 5
 * ```
 *
 * @param a - The first point
 * @param b - The second point
 * @returns The Euclidean distance between points a and b
 * @throws {@link InvalidPointError} if coordinates are NaN
 * @since 1.2.0
 * @category Geometry
 * @public
 */
export function distance(a: Point, b: Point): number {
  return Math.sqrt((b.x - a.x) ** 2 + (b.y - a.y) ** 2);
}

Supported Tags

TagDescription
@param nameDescribe a parameter
@returnsDescribe return value
@throwsDocument thrown errors
@exampleCode example
@remarksExtended description
@seeCross-reference link
@deprecatedMark as deprecated with reason
@sinceVersion introduced
@categoryGroup into category
@groupGroup into custom group
@publicMark as public API
@internalMark as internal (excludable)
@alphaAlpha release stability
@betaBeta release stability
@typeParam TDescribe a type parameter
@defaultValueDocument default value
@linkInline link to another symbol
@inheritDocInherit documentation from parent

Documenting Types

/**
 * Configuration options for the HTTP client.
 * @category Configuration
 */
export interface ClientConfig {
  /** Base URL for all API requests */
  baseUrl: string;

  /** Request timeout in milliseconds @defaultValue 30000 */
  timeout?: number;

  /** Custom headers to include with every request */
  headers?: Record<string, string>;
}

/**
 * Available log levels ordered by severity.
 * @category Logging
 */
export enum LogLevel {
  /** Detailed debug information */
  DEBUG = 'debug',
  /** General informational messages */
  INFO = 'info',
  /** Warning conditions */
  WARN = 'warn',
  /** Error conditions */
  ERROR = 'error',
}

Advanced Usage

Multiple Entry Points

{
  "entryPoints": [
    "src/core/index.ts",
    "src/utils/index.ts",
    "src/types/index.ts"
  ],
  "entryPointStrategy": "expand"
}

Monorepo Support

{
  "entryPoints": ["packages/*"],
  "entryPointStrategy": "packages"
}
PluginDescription
typedoc-plugin-markdownOutput as Markdown files
typedoc-plugin-mdn-linksLink web APIs to MDN docs
typedoc-plugin-rename-defaultsBetter names for default exports
typedoc-plugin-merge-modulesMerge multiple modules into one
typedoc-plugin-missing-exportsDocument non-exported types

Troubleshooting

IssueSolution
Types not resolvedEnsure tsconfig.json includes all source files
Missing documentationAdd TSDoc comments; check exclude patterns
Broken cross-referencesUse {@link SymbolName} with correct fully-qualified name
Private members appearingSet excludePrivate: true in config
Slow generationUse --emit doc to skip type checking
Plugin not loadingVerify plugin is installed and listed in plugin array
Output validation errorsRun with --validation to see specific issues
Monorepo packages not foundUse entryPointStrategy: "packages" with correct glob