typescript-api-extractor
v1.0.0-beta.7
Published
Extracts API description from TypeScript code
Downloads
77,395
Readme
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.
Features
- 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
Installation
npm install typescript-api-extractoror with yarn:
yarn add typescript-api-extractoror with pnpm:
pnpm add typescript-api-extractorQuick start
import {
createProgram,
loadConfig,
parseFromProgram,
type ModuleNode,
} from 'typescript-api-extractor';
// Load TypeScript configuration
const config = loadConfig('./tsconfig.json');
const program = 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);
} catch (error) {
console.error(`Failed to parse ${file}:`, error);
}
}Documentation
- Usage - parsing a project or a single file, filtering properties, limiting object expansion, and handling parser warnings.
- API reference - exported functions,
ParserOptions, and the parser warning types. - Output format - the extracted module model, type operator representation, and an annotated example.
- Architecture - how the parser layers, resolver pipeline, and model helpers fit together.
Requirements
- Node.js: >= 22
License
This project is licensed under the terms of the MIT license.
Acknowledgments
This project was started as a fork of typescript-to-proptypes created by Kristoffer K..
