Extracts API description from TypeScript code
npm install typescript-api-extractor


A utility for extracting API descriptions from TypeScript definitions using the TypeScript Compiler API. This tool analyzes TypeScript source code and generates structured metadata about exported functions, components, interfaces, types, and more.
- π Extract API information from TypeScript source files
- βοΈ React component analysis with prop types and documentation
- π·οΈ Type definitions including interfaces, enums, and type aliases
- π JSDoc comments parsing and extraction
- π Reference resolution for complex type relationships
- π― Selective parsing of specific files or entire projects
``bash`
npm install typescript-api-extractor
or with yarn:
`bash`
yarn add typescript-api-extractor
or with pnpm:
`bash`
pnpm add typescript-api-extractor
`typescript
import ts from 'typescript';
import { loadConfig, parseFromProgram, type ModuleNode } from 'typescript-api-extractor';
// Load TypeScript configuration
const config = loadConfig('./tsconfig.json');
const program = ts.createProgram(config.fileNames, config.options);
// Parse all files in the project
for (const file of config.fileNames) {
try {
const moduleInfo: ModuleNode = parseFromProgram(file, program);
console.log(Extracted API from ${file}:, moduleInfo);Failed to parse ${file}:
} catch (error) {
console.error(, error);`
}
}
Loads and parses a TypeScript configuration file.
- Parameters:
- tsConfigPath: Path to the tsconfig.json file{ options: ts.CompilerOptions, fileNames: string[] }
- Returns:
Parses a single TypeScript file and returns the extracted API information.
- Parameters:
- filePath: Path to the TypeScript file to parseoptions
- : TypeScript compiler optionsparserOptions
- : Optional parser configurationModuleNode
- Returns:
Parses a file from an existing TypeScript program for better performance when parsing multiple files.
- Parameters:
- filePath: Path to the file to parseprogram
- : TypeScript program instanceparserOptions
- : Optional parser configurationModuleNode
- Returns:
The parser accepts optional configuration through the ParserOptions interface:
`typescript`
interface ParserOptions {
includePrivateMembers?: boolean;
followReferences?: boolean;
maxDepth?: number;
}
The parser returns a ModuleNode object with the following structure:
`typescript
interface ModuleNode {
name: string;
exports: ExportNode[];
}
interface ExportNode {
name: string;
type: TypeNode;
documentation?: DocumentationNode;
}
`
TypeNode represents a TypeScript type. There are multiple classes of types. See the contents of the src/models/types directory to discover them.
For a React component like this:
`typescript
interface Props {
/* The title to display /
title: string;
/* Whether the component is disabled /
disabled?: boolean;
}
export function MyComponent(props: Props) {
return
The extractor would produce:
`json
{
"name": "MyComponent",
"exports": [
{
"name": "MyComponent",
"type": {
"kind": "component",
"name": "MyComponent",
"props": [
{
"name": "title",
"type": {
"kind": "intrinsic",
"intrinsic": "string"
},
"optional": false,
"documentation": {
"description": "The title to display"
}
},
{
"name": "disabled",
"type": {
"kind": "intrinsic",
"intrinsic": "boolean"
},
"optional": true,
"documentation": {
"description": "Whether the component is disabled"
}
}
]
}
}
]
}
`Requirements
- Node.js: >= 22
- TypeScript: ^5.8 (peer dependency)
Make sure you have TypeScript installed in your project:
`bash
npm install typescript
``This project is licensed under the terms of the MIT license.
This project was started as a fork of typescript-to-proptypes created by Kristoffer K..