Skip to content

TypeScript API

TypeScript analysis is beta. TypeScriptAnalysis exposes a typed symbol table, classes, interfaces, enums, decorators, and a call graph through nearly the same API as Java and Python. Its symbol table and call graph are solid; framework entrypoint detection is the main gap (see the note below).

CLDK.typescript(project_path=...) returns a TypeScriptAnalysis object backed by the codeanalyzer-ts backend, which parses and resolves a project in a single pass with ts-morph (the TypeScript compiler API). The same TypeChecker that builds the symbol table resolves call targets, so call-graph derivation reuses existing resolution.

flowchart LR
    T[TypeScript project] --> A["CLDK.typescript(project_path)"]
    A --> M[ts-morph / TypeChecker]
    M --> S[Symbol table]
    M --> CG["Call graph (tsc + RTA)"]

Project path only. TypeScript analysis needs a project directory of valid TypeScript/TSX sources (there is no single-string source_code mode). Pass it as project_path:

from cldk import CLDK
from cldk.analysis import AnalysisLevel
analysis = CLDK.typescript(
project_path="/path/to/ts/project",
analysis_level=AnalysisLevel.call_graph, # required for the call graph
)
print(analysis.get_classes()) # -> dict[str, TSClass]
graph = analysis.get_call_graph() # -> networkx.DiGraph

Not yet implemented

get_entry_point_methods() and get_service_entry_point_methods() raise NotImplementedError: framework entrypoint detection is not implemented in the codeanalyzer-ts backend yet. To analyze TypeScript at scale through a shared Neo4j graph, see Analysis at scale.

Source on GitHub cldk 1.2.0

API reference generated from cldk 1.2.0.

TypeScript analysis facade.

Thin, read-only query layer over the canonical TSApplication produced by the codeanalyzer-typescript backend. Mirrors the method vocabulary of JavaAnalysis / PythonAnalysis (there is no shared base class, the facades match by convention) and, like those, delegates all indexing and query work to its backend (TSCodeanalyzer).

class TypeScriptAnalysis

Analysis facade for TypeScript projects.

Delegates every query to a backend. Two interchangeable backends exist, both exposing the same method surface:

  • TSCodeanalyzer (default), walks the in-memory pydantic TSApplication / a NetworkX call graph built from analysis.json;
  • TSNeo4jBackend, answers the same get_* queries with Cypher over the graph codeanalyzer-typescript emits with --emit neo4j. Selected by passing neo4j_config.
NameTypeDescription
project_dir
analysis_level
target_files
eager_analysis
backend_configTSBackend
backendTSAnalysisBackend
applicationTSApplication
get_application_view() -> TSApplication
get_symbol_table() -> Dict[str, TSModule]
get_modules() -> List[TSModule]
get_call_graph() -> nx.DiGraph

NetworkX DiGraph of callable signatures (and phantom external symbols) connected by the identity-only call edges.

get_external_symbols() -> Dict[str, TSExternalSymbol]

The phantom (external) call targets, imported/required library members the call graph points at (e.g. node:fs.readFileSync, js-yaml.load). Useful for source→sink reachability.

get_call_graph_json() -> str
get_callers(target_class_name: str, target_method_declaration: str | None = None) -> Dict

Callers of a method, with the connecting call-graph edge metadata (provenance / tags). Pass a bare signature as the first argument for module-level functions or external (phantom) targets.

get_callees(source_class_name: str, source_method_declaration: str | None = None) -> Dict

Callees of a method, with the connecting call-graph edge metadata.

get_class_call_graph(qualified_class_name: str, method_signature: str | None = None) -> List[Tuple[str, str]]

Call-graph edges reachable from a class (or one of its methods).

get_class_hierarchy() -> nx.DiGraph

Inheritance/implementation graph: an edge child → base for every base_class.

get_call_sites(qualified_callable_name: str) -> List[TSCallsite]

The rich, syntactic call sites inside a callable (receiver/argument types, resolved callee_signature, source position).

get_calling_lines(target_signature: str) -> List[int]

Sorted source lines anywhere in the project where target_signature is invoked.

get_call_targets(source_signature: str) -> Set[str]

The call targets invoked from a callable, derived from its call sites.

TypeScriptAnalysis.get_entry_point_methods
Section titled “TypeScriptAnalysis.get_entry_point_methods”
get_entry_point_methods() -> Dict[str, Dict[str, TSCallable]]

Return methods identified as application entry points.

Not yet supported: the codeanalyzer-typescript backend’s entrypoint detection is a stub placeholder, the entrypoints list on each TSCallable/TSClass is always empty (level-2 finders are not implemented), so this method exists for API parity with PythonAnalysis / JavaAnalysis but raises.

Raises:

  • NotImplementedError: Always.
TypeScriptAnalysis.get_service_entry_point_methods
Section titled “TypeScriptAnalysis.get_service_entry_point_methods”
get_service_entry_point_methods(**kwargs) -> Dict[str, Dict[str, TSCallable]]

Return methods that serve as service entry points (e.g. Express/NestJS routes).

Not yet supported; see get_entry_point_methods.

Raises:

  • NotImplementedError: Always.
get_classes() -> Dict[str, TSClass]
get_class(qualified_class_name: str) -> TSClass | None
TypeScriptAnalysis.get_classes_by_criteria
Section titled “TypeScriptAnalysis.get_classes_by_criteria”
get_classes_by_criteria(inclusions: List[str] | None = None, exclusions: List[str] | None = None) -> Dict[str, TSClass]
get_interfaces() -> Dict[str, TSInterface]
get_enums() -> Dict[str, TSEnum]
get_enum_members(qualified_enum_name: str) -> List[TSEnumMember]
get_type_aliases() -> Dict[str, TSTypeAlias]
get_functions() -> Dict[str, TSCallable]

Top-level (module/namespace) functions.

get_methods() -> Dict[str, Dict[str, TSCallable]]

All methods grouped by class/interface signature.

get_methods_in_class(qualified_class_name: str) -> Dict[str, TSCallable]
get_method(qualified_class_name: str, qualified_method_name: str) -> TSCallable | None
get_method_parameters(qualified_class_name: str, qualified_method_name: str) -> List[str]
get_constructors(qualified_class_name: str) -> Dict[str, TSCallable]
get_fields(qualified_class_name: str) -> List[TSClassAttribute]
TypeScriptAnalysis.get_interface_properties
Section titled “TypeScriptAnalysis.get_interface_properties”
get_interface_properties(qualified_interface_name: str) -> List[TSClassAttribute]
get_imports() -> Dict[str, List[TSImport]]
get_exports() -> Dict[str, List[TSExport]]
get_variables() -> Dict[str, List[TSVariableDeclaration]]

Module-level variable declarations per file.

get_typescript_file(qualified_name: str) -> str | None

File path declaring the class/interface/enum/callable with the given signature.

get_typescript_module(file_path: str) -> TSModule | None
get_nested_classes(qualified_class_name: str) -> List[TSClass]
get_sub_classes(qualified_class_name: str) -> Dict[str, TSClass]
get_extended_classes(qualified_class_name: str) -> List[str]

The base types a class extends (base_classes minus the implemented interfaces).

TypeScriptAnalysis.get_implemented_interfaces
Section titled “TypeScriptAnalysis.get_implemented_interfaces”
get_implemented_interfaces(qualified_class_name: str) -> List[str]
get_decorators(qualified_callable_name: str) -> List[TSDecorator]

Structured decorators (with arguments) applied to a callable.

get_class_decorators(qualified_class_name: str) -> List[TSDecorator]

Structured decorators (with arguments) applied to a class.

TypeScriptAnalysis.get_methods_with_decorators
Section titled “TypeScriptAnalysis.get_methods_with_decorators”
get_methods_with_decorators(decorators: List[str]) -> Dict[str, List[str]]

Map each requested decorator name to the signatures of callables carrying it. TS decorators are captured structurally, so this is populatable at level 1.

TypeScriptAnalysis.get_classes_with_decorators
Section titled “TypeScriptAnalysis.get_classes_with_decorators”
get_classes_with_decorators(decorators: List[str]) -> Dict[str, List[str]]

Map each requested decorator name to the signatures of classes carrying it.

TypeScript model package, identity-only schema mirror of codeanalyzer-ts/src/schema.ts.

class TSApplication(_Base)

The root analysis object emitted as analysis.json.

NameTypeDescription
symbol_tableDict[str, TSModule]
call_graphList[TSCallEdge]
external_symbolsDict[str, TSExternalSymbol]
class TSCallEdge(_Base)

Identity-only call-graph edge. source/target are TSCallable.signature strings.

NameTypeDescription
sourcestr
targetstr
typeLiteral['CALL_DEP']
weightint
provenanceList[str]
tagsDict[str, str]
class TSCallable(_Base)

A function / method / constructor / accessor / arrow function.

NameTypeDescription
namestr
pathstr
signaturestr
commentsList[TSComment]
decoratorsList[TSDecorator]
parametersList[TSCallableParameter]
type_parametersList[TSTypeParameter]
return_typeOptional[str]
codeOptional[str]
start_lineint
end_lineint
code_start_lineint
accessed_symbolsList[TSSymbol]
call_sitesList[TSCallsite]
inner_callablesDict[str, 'TSCallable']
inner_classesDict[str, 'TSClass']
local_variablesList[TSVariableDeclaration]
cyclomatic_complexityint
entrypointsList['TSEntrypoint']
kindstr
accessibilityOptional[str]
is_staticbool
is_abstractbool
is_asyncbool
is_generatorbool
is_optionalbool
is_readonlybool
is_exportedbool
is_ambientbool
is_implicitbool
accessor_kindOptional[str]
overload_signaturesList[TSOverloadSignature]
class TSCallableParameter(_Base)

A function / method parameter.

NameTypeDescription
namestr
typeOptional[str]
default_valueOptional[str]
is_optionalbool
is_restbool
is_readonlybool
accessibilityOptional[str]
decoratorsList[TSDecorator]
start_lineint
end_lineint
start_columnint
end_columnint
class TSCallsite(_Base)

Rich per-call metadata, attached to the caller. callee_signature is backfilled by the resolver call graph.

NameTypeDescription
method_namestr
receiver_exprOptional[str]
receiver_typeOptional[str]
argument_typesList[str]
type_argumentsList[str]
return_typeOptional[str]
callee_signatureOptional[str]
is_constructor_callbool
is_optional_chainbool
start_lineint
start_columnint
end_lineint
end_columnint
class TSClass(_Base)

A class declaration.

NameTypeDescription
namestr
signaturestr
commentsList[TSComment]
codeOptional[str]
decoratorsList[TSDecorator]
base_classesList[str]
implements_typesList[str]
type_parametersList[TSTypeParameter]
methodsDict[str, TSCallable]
attributesDict[str, TSClassAttribute]
inner_classesDict[str, 'TSClass']
entrypointsList['TSEntrypoint']
is_abstractbool
is_exportedbool
is_ambientbool
start_lineint
end_lineint
class TSClassAttribute(_Base)

A class property / field (also covers constructor parameter-properties).

NameTypeDescription
namestr
typeOptional[str]
commentsList[TSComment]
decoratorsList[TSDecorator]
initializerOptional[str]
accessibilityOptional[str]
is_staticbool
is_readonlybool
is_optionalbool
is_abstractbool
start_lineint
end_lineint
class TSComment(_Base)

A comment or JSDoc block.

NameTypeDescription
contentstr
is_docstringbool
start_lineint
end_lineint
start_columnint
end_columnint
class TSDecorator(_Base)

A decorator applied to a class / member / parameter (structured, with arguments).

NameTypeDescription
namestr
qualified_nameOptional[str]
positional_argumentsList[str]
keyword_argumentsDict[str, str]
start_lineint
end_lineint
start_columnint
end_columnint
class TSEntrypoint(_Base)

A framework entrypoint (populated by level-2 finders; empty for level 1). Embedded on the owning TSCallable/TSClass, so it carries no signature/source_file of its own.

NameTypeDescription
frameworkstr
detection_sourcestr
route_pathOptional[str]
http_methodsList[str]
tagsDict[str, str]
class TSEnum(_Base)

An enum declaration (TS node kind).

NameTypeDescription
namestr
signaturestr
commentsList[TSComment]
codeOptional[str]
membersList[TSEnumMember]
is_constbool
is_exportedbool
is_ambientbool
start_lineint
end_lineint
class TSEnumMember(_Base)

A member of an enum.

NameTypeDescription
namestr
valueOptional[str]
start_lineint
end_lineint
class TSExport(_Base)

A TypeScript export / re-export binding.

NameTypeDescription
moduleOptional[str]
namestr
aliasOptional[str]
is_type_onlybool
export_kindstr
start_lineint
end_lineint
start_columnint
end_columnint
class TSExternalSymbol(_Base)

A WALA-style phantom node: a synthetic stub for a call target OUTSIDE the project (an imported/required library member). An edge’s target byte-matches either a real TSCallable.signature or a TSExternalSymbol.signature, so the call graph stays dangling-free while still recording external (e.g. sink) calls.

Slim: the map key in TSApplication.external_symbols IS the signature (e.g. commander.parse), and membership already means external, so neither is repeated here.

NameTypeDescription
namestr
modulestr
class TSImport(_Base)

A TypeScript import binding (one entry per imported name).

NameTypeDescription
modulestr
namestr
aliasOptional[str]
is_type_onlybool
import_kindstr
start_lineint
end_lineint
start_columnint
end_columnint
class TSInterface(_Base)

An interface declaration (TS node kind).

NameTypeDescription
namestr
signaturestr
commentsList[TSComment]
codeOptional[str]
base_classesList[str]
type_parametersList[TSTypeParameter]
methodsDict[str, TSCallable]
propertiesDict[str, TSClassAttribute]
call_signaturesList[str]
index_signaturesList[str]
is_exportedbool
is_ambientbool
start_lineint
end_lineint
class TSModule(_Base)

A compilation unit (a .ts/.tsx file).

NameTypeDescription
file_pathstr
module_namestr
importsList[TSImport]
exportsList[TSExport]
commentsList[TSComment]
classesDict[str, TSClass]
interfacesDict[str, TSInterface]
enumsDict[str, TSEnum]
type_aliasesDict[str, TSTypeAlias]
functionsDict[str, TSCallable]
namespacesDict[str, TSNamespace]
variablesList[TSVariableDeclaration]
is_tsxbool
is_declaration_filebool
content_hashOptional[str]
last_modifiedOptional[float]
file_sizeOptional[int]
class TSNamespace(_Base)

A namespace / module block (TS node kind), recursive container.

NameTypeDescription
namestr
signaturestr
commentsList[TSComment]
classesDict[str, TSClass]
interfacesDict[str, TSInterface]
enumsDict[str, TSEnum]
type_aliasesDict[str, TSTypeAlias]
functionsDict[str, TSCallable]
variablesList[TSVariableDeclaration]
namespacesDict[str, 'TSNamespace']
is_exportedbool
is_ambientbool
start_lineint
end_lineint
class TSOverloadSignature(_Base)

An overload signature attached to the implementation callable.

NameTypeDescription
parametersList[TSCallableParameter]
return_typeOptional[str]
type_parametersList[TSTypeParameter]
start_lineint
end_lineint
class TSSymbol(_Base)

A symbol referenced or declared in code.

NameTypeDescription
namestr
scopestr
kindstr
typeOptional[str]
qualified_nameOptional[str]
is_builtinbool
linenoint
col_offsetint
class TSTypeAlias(_Base)

A type-alias declaration (TS node kind).

NameTypeDescription
namestr
signaturestr
commentsList[TSComment]
codeOptional[str]
aliased_typestr
type_parametersList[TSTypeParameter]
is_exportedbool
is_ambientbool
start_lineint
end_lineint
class TSTypeParameter(_Base)

A generic type parameter, e.g. T extends Base = Default.

NameTypeDescription
namestr
constraintOptional[str]
defaultOptional[str]
class TSVariableDeclaration(_Base)

A variable / const / let declaration.

NameTypeDescription
namestr
typeOptional[str]
initializerOptional[str]
valueOptional[Any]
scopestr
declaration_kindstr
is_readonlybool
is_exportedbool
start_lineint
end_lineint
start_columnint
end_columnint