typescript-api-extractor is a utility designed to analyze TypeScript source code and generate structured metadata about its exported API. It leverages the TypeScript Compiler API to extract information on functions, React components, interfaces, types, enums, and their associated JSDoc comments. The package is currently in beta (v1.0.0-beta.3 as of the last release), indicating active development with potential for API changes, though it appears to have a consistent release cadence for bug fixes and new features. Its key differentiators include specialized React component analysis, robust JSDoc parsing, intelligent reference resolution for complex types, and the ability to selectively parse files or entire projects, outputting a detailed `ModuleNode` structure for programmatic consumption. This tool is particularly useful for generating documentation, schema definitions, or other forms of API introspection directly from TypeScript codebases.
npm install typescript-api-extractorVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to load a `tsconfig.json`, create a TypeScript `Program` instance, and then iterate through all project files to extract and log their API definitions using `parseFromProgram`.
Always pin to a specific version or use caret ranges cautiously. Review release notes carefully when upgrading to new beta versions.
Upgrade to `typescript-api-extractor@1.0.0-beta.3` or newer to ensure compatibility and correct recognition of `memo`'d components with TypeScript 6.
Ensure your development and build environments use Node.js v22 or higher. Use a Node Version Manager (e.g., `nvm` or `volta`) to manage Node.js versions.
Verify the path to your `tsconfig.json` is correct and accessible from where the script is run. Use an absolute path or a relative path correctly pointing to the file. Ensure the file exists and is readable.
Ensure your project is configured for ES Modules (e.g., `"type": "module"` in `package.json`), or compile your TypeScript with an ES Module target. If sticking to CommonJS, you might need to use `const { parseFromProgram } = await import('typescript-api-extractor');` (dynamic import) or verify the package's CommonJS output (if any) and adjust your `require` statement accordingly, though ESM is the primary target.Migrate your consuming code to use ES Module `import` syntax or change your CommonJS `require()` call to a dynamic `import()`: `const { loadConfig } = await import('typescript-api-extractor');` within an `async` function.