ts_helpers.ts

Declarations
#

TypeScript compiler API helpers for extracting metadata from source code.

All functions are prefixed with ts_ for clarity.

12 declarations

view source

ModuleExportsAnalysis
#

ts_helpers.ts view source

ModuleExportsAnalysis

Result of analyzing a module's exports.

module_comment

Module-level documentation comment.

type string

declarations

All exported declarations with their metadata (excludes same-name re-exports).

type Array<DeclarationJson>

re_exports

Same-name re-exports (for building also_exported_from in post-processing).

type Array<ReExportInfo>

ReExportInfo
#

ts_helpers.ts view source

ReExportInfo

Information about a same-name re-export. Used for post-processing to build also_exported_from arrays.

name

Name of the re-exported declaration.

type string

original_module

Module path (relative to src/lib) where the declaration is originally declared.

type string

ts_analyze_declaration
#

ts_helpers.ts view source

(symbol: Symbol, source_file: SourceFile, checker: TypeChecker): TsDeclarationAnalysis

Analyze a TypeScript symbol and extract rich metadata.

This is a high-level function that combines TSDoc parsing with TypeScript type analysis to produce complete declaration metadata. Suitable for use in documentation generators, IDE integrations, and other tooling.

symbol

The TypeScript symbol to analyze

type Symbol

source_file

The source file containing the symbol

type SourceFile

checker

The TypeScript type checker

type TypeChecker

returns

TsDeclarationAnalysis

Complete declaration metadata including docs, types, and parameters, plus nodocs flag

ts_analyze_module_exports
#

ts_helpers.ts view source

(source_file: SourceFile, checker: TypeChecker): ModuleExportsAnalysis

Analyze all exports from a TypeScript source file.

Extracts the module-level comment and all exported declarations with complete metadata. Handles re-exports by: - Same-name re-exports: tracked in re_exports for also_exported_from building - Renamed re-exports: included as new declarations with alias_of metadata

This is a high-level function suitable for building documentation, API explorers, or analysis tools.

source_file

The TypeScript source file to analyze

type SourceFile

checker

The TypeScript type checker

type TypeChecker

returns

ModuleExportsAnalysis

Module comment, array of analyzed declarations, and re-export information

ts_create_program
#

ts_helpers.ts view source

(log: { warn: (message: string) => void; }): Program | null

Create TypeScript program for analysis.

log

type { warn: (message: string) => void; }

returns

Program | null

ts_extract_class_info
#

ts_helpers.ts view source

(node: Node, _symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }): void

Extract class information with rich member metadata.

node

type Node

_symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

returns

void

ts_extract_function_info
#

ts_helpers.ts view source

(node: Node, symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }, tsdoc: TsdocParsedComment | undefined): void

Extract function/method information including parameters with descriptions and default values.

node

type Node

symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

tsdoc

type TsdocParsedComment | undefined

returns

void

ts_extract_module_comment
#

ts_helpers.ts view source

(source_file: SourceFile): string | undefined

Extract module-level comment.

Only accepts JSDoc/TSDoc comments (/** ... *\/) followed by a blank line to distinguish them from identifier-level comments. This prevents accidentally treating function/class comments as module comments. Module comments can appear after imports.

source_file

type SourceFile

returns

string | undefined

ts_extract_type_info
#

ts_helpers.ts view source

(node: Node, _symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }): void

Extract type/interface information with rich property metadata.

node

type Node

_symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

returns

void

ts_extract_variable_info
#

ts_helpers.ts view source

(node: Node, symbol: Symbol, checker: TypeChecker, declaration: { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; ... 19 more ...; alias_of?: { ...; } | undefined; }): void

Extract variable information.

node

type Node

symbol

type Symbol

checker

type TypeChecker

declaration

type { [x: string]: unknown; name: string; kind: "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"; doc_comment?: string | undefined; type_signature?: string | undefined; ... 17 more ...; alias_of?: { ...; } | undefined; }

returns

void

ts_infer_declaration_kind
#

ts_helpers.ts view source

(symbol: Symbol, node: Node): "function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"

Infer declaration kind from symbol and node.

symbol

type Symbol

node

type Node

returns

"function" | "type" | "json" | "variable" | "class" | "constructor" | "component" | "css"

TsDeclarationAnalysis
#

ts_helpers.ts view source

TsDeclarationAnalysis

Result of analyzing a single declaration.

declaration

The analyzed declaration metadata.

type DeclarationJson

nodocs

Whether the declaration is marked

type boolean

Depends on
#

Imported by
#