See the usage guide for worked examples and the output format for the returned data shape.
Re-export of TypeScript's createProgram from the TypeScript version bundled
with typescript-api-extractor. It has the same overloads/signature as
typescript.createProgram and returns a Program.
Loads and parses a TypeScript configuration file.
- Parameters:
tsConfigPath: Path to thetsconfig.jsonfile
- Returns:
{ options: CompilerOptions, fileNames: string[] }
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 configuration
- Returns:
ResolvedModuleNodeby default, orSyntaxOnlyModuleNodewhenparserOptions.typeOperatorOutputis the literal'syntaxOnly'. A dynamicParserOptionsvalue returns their union.
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 configuration
- Returns:
ResolvedModuleNodeby default, orSyntaxOnlyModuleNodewhenparserOptions.typeOperatorOutputis the literal'syntaxOnly'. A dynamicParserOptionsvalue returns their union.
The parser accepts optional configuration through the ParserOptions interface:
interface ParserOptions {
shouldInclude?: (data: { name: string; depth: number }) => boolean | undefined;
shouldResolveObject?: (data: {
name: string;
propertyCount: number;
depth: number;
propertyDepth: number;
}) => boolean | undefined;
includeExternalTypes?: boolean;
typeOperatorOutput?: 'resolved' | 'syntaxOnly';
onWarning?: (warning: ParserWarning) => void;
}shouldResolveObject decides whether an object's shape is expanded or reduced to
a bare object. Returning undefined falls back to
(propertyDepth === 0 || propertyCount <= 50) && depth <= 10.
depth counts every type on the resolution stack, while propertyDepth counts
only the property (and index signature) values traversed to reach the object. A
propertyDepth of 0 means the object is the export's own type or something
reached from it through composition alone - aliases, unions, intersections, and
the parameter and return types of its call signatures. The default rule applies
the property-count limit only above that, so a large component prop list is
reported in full while its individual props stay bounded.
When onWarning is omitted, recoverable parser warnings are printed with
console.warn. Provide onWarning to collect or format them yourself.
type ParserWarning =
| UnsupportedTypeFallbackWarning
| MissingEnumDeclarationWarning
| MissingDefaultExportSymbolWarning;
interface ParserWarningBase {
message: string;
filePath: string;
line: number;
column: number;
parsedSymbolStack: string[];
}
interface UnsupportedTypeFallbackWarning extends ParserWarningBase {
code: 'unsupported-type-fallback';
typeFlags: string[];
typeText: string;
sourceText?: string;
}
interface MissingEnumDeclarationWarning extends ParserWarningBase {
code: 'missing-enum-declaration';
enumName: string;
}
interface MissingDefaultExportSymbolWarning extends ParserWarningBase {
code: 'missing-default-export-symbol';
sourceText: string;
}