ts-morph
RepositoryFreeTypeScript Compiler API wrapper for static analysis and programmatic code changes.
Capabilities13 decomposed
in-memory ast manipulation with deferred persistence
Medium confidenceWraps TypeScript Compiler API objects to provide an object-oriented interface for navigating and modifying Abstract Syntax Trees while maintaining all changes in memory until explicitly saved to disk. Uses a Node-based wrapper system that maps compiler API nodes to higher-level abstractions, enabling safe mutations without immediate file I/O. Changes accumulate in memory and are flushed to the file system only when saveSourceFile() or saveSourceFiles() is called, allowing batch operations and rollback scenarios.
Implements a wrapper-based abstraction over TypeScript Compiler API that decouples AST mutations from file I/O, allowing in-memory accumulation of changes across multiple files before batch persistence. This differs from direct Compiler API usage which requires managing file writes manually.
Provides safer, more ergonomic in-memory code mutation than raw TypeScript Compiler API while maintaining full fidelity to the compiler's AST model, unlike higher-level tools like Babel which use their own AST representation.
semantic-aware code navigation and traversal
Medium confidenceProvides a comprehensive object-oriented API for traversing AST nodes with semantic awareness through the TypeChecker interface, enabling queries like 'find all usages of this symbol' and 'get the type of this expression'. Navigation methods include getParent(), getChildren(), forEachChild(), and specialized accessors for declaration kinds (getClass(), getFunction(), getInterface()). The system wraps compiler API's SyntaxKind and TypeFlags enums into strongly-typed Node subclasses, making traversal type-safe and IDE-friendly with autocomplete.
Wraps TypeScript's TypeChecker to provide semantic-aware navigation through a strongly-typed Node hierarchy, where each SyntaxKind maps to a specific TypeScript class (ClassDeclaration, FunctionDeclaration, etc.). This enables IDE-like autocomplete and type safety for AST traversal, unlike raw Compiler API which requires manual SyntaxKind checking.
Combines syntactic AST traversal with semantic type information in a single unified API, whereas alternatives like Babel require separate passes for syntax and type analysis, or tools like ESLint use a different AST model entirely.
syntax-aware code formatting and whitespace preservation
Medium confidenceProvides APIs for querying and manipulating whitespace, formatting, and syntax details through methods like getLeadingTrivia(), getTrailingTrivia(), and getFullText(). Preserves existing formatting when modifying code, allowing surgical edits that don't reformat the entire file. Supports querying line and column positions, getting source text with or without trivia, and understanding the syntactic structure including comments and whitespace.
Provides explicit APIs for accessing and manipulating trivia (comments, whitespace) separately from syntax nodes, enabling surgical edits that preserve formatting. This is more sophisticated than tools that treat trivia as part of the node, which can lose formatting information.
Preserves formatting and comments during code modifications, whereas raw Compiler API loses trivia information, and template-based generators require reformatting after generation.
typescript-specific language feature support (generics, unions, intersections)
Medium confidenceProvides comprehensive support for TypeScript-specific type features through specialized node classes and type introspection APIs. Handles generics with type parameters and type arguments, union and intersection types, conditional types, mapped types, and type queries. Enables querying and modifying these features through methods like getTypeArguments(), getConstraint(), and getTypeParameters() on relevant node types.
Provides dedicated node classes and APIs for TypeScript-specific type features (generics, unions, intersections, conditional types, mapped types), enabling type-aware code generation and analysis. This level of support is unique to TypeScript-focused tools.
Handles advanced TypeScript type features that generic AST tools cannot, making it suitable for sophisticated type-aware code generation and analysis that requires understanding of the full TypeScript type system.
incremental compilation and caching for performance optimization
Medium confidenceImplements caching and incremental compilation strategies to optimize performance when working with large projects. Caches parsed ASTs and type information to avoid re-parsing unchanged files, and supports incremental updates when source files are modified. The Project class manages this caching internally, reusing compiler state across multiple operations to reduce redundant work.
Implements automatic caching and incremental compilation within the Project class, reusing compiler state across operations to avoid redundant parsing and type checking. This is transparent to the user but significantly improves performance for multi-operation workflows.
Provides automatic performance optimization without requiring manual cache management, whereas raw Compiler API requires creating new compiler instances for each operation, leading to redundant work.
declaration-aware code generation and modification
Medium confidenceProvides specialized APIs for creating and modifying TypeScript declarations (classes, interfaces, functions, imports) through a structure-based system that abstracts away low-level AST node creation. Uses a StructurePrinterFactory pattern to convert high-level structure objects (ClassDeclarationStructure, FunctionDeclarationStructure, etc.) into AST nodes, enabling developers to add methods to classes, create new interfaces, or modify function signatures without manually constructing SyntaxNodes. Supports JSDoc generation, decorators, access modifiers, and type annotations through the structure API.
Implements a StructurePrinterFactory pattern that converts high-level structure objects into AST nodes, abstracting away the complexity of manually constructing SyntaxNodes. This enables declarative code generation where developers describe 'what' (a class with these methods) rather than 'how' (create ClassDeclaration node, add MethodDeclaration children, etc.).
Provides a more ergonomic and type-safe API for code generation than raw Compiler API, and maintains full TypeScript semantic fidelity unlike template-based generators which produce strings that must be parsed separately.
import and export statement manipulation
Medium confidenceProvides specialized APIs for analyzing and modifying import/export declarations through dedicated classes (ImportDeclaration, ExportDeclaration, ExportSpecifier) that abstract away the complexity of managing module specifiers, named imports, default imports, and re-exports. Supports operations like addImportDeclaration(), removeImportDeclaration(), and getImportDeclarations() with filtering by module name. Handles both ES6 module syntax and CommonJS require patterns, and can automatically organize imports or detect circular dependencies.
Provides dedicated ImportDeclaration and ExportDeclaration classes that wrap the compiler API's import/export node types, offering high-level methods like addImportDeclaration() that handle the complexity of managing module specifiers, named bindings, and default exports. Abstracts away the need to manually construct ImportSpecifier and ExportSpecifier nodes.
Simpler and more ergonomic than raw Compiler API for import/export manipulation, and handles both ES6 and CommonJS patterns in a unified API, whereas alternatives like jscodeshift require separate handling for each module system.
type system introspection and querying
Medium confidenceExposes TypeScript's type system through a wrapper API that allows querying type information for expressions, declarations, and symbols. Provides methods like getType(), getTypeAtLocation(), and getSymbolAtLocation() that return Type and Symbol objects with properties for checking type kinds (isStringLiteral(), isUnion(), isIntersection()), accessing type arguments, and resolving symbol definitions. Integrates with TypeChecker to enable semantic analysis without requiring developers to interact with the low-level Compiler API directly.
Wraps TypeScript's TypeChecker and Type/Symbol APIs to provide a more ergonomic interface for type introspection, with helper methods for common type checks (isStringLiteral(), isUnion()) and type traversal. Abstracts away the complexity of working with TypeScript's internal type representation.
Provides direct access to TypeScript's actual type system (not an approximation), making it more accurate than tools like Babel or ESLint which use simplified type models, while being more ergonomic than raw Compiler API.
file system abstraction with in-memory and real file system support
Medium confidenceImplements a FileSystemHost abstraction layer that decouples ts-morph from the underlying file system, supporting both real file system operations and in-memory virtual file systems. The abstraction allows creating a Project with a custom FileSystemHost implementation, enabling scenarios like testing without disk I/O, running in browser environments, or using custom storage backends. Provides methods like readFileSync(), writeFileSync(), and directoryExistsSync() that can be overridden to implement alternative storage strategies.
Implements a pluggable FileSystemHost interface that allows swapping the underlying file system implementation without changing application code. This enables the same ts-morph code to work with real file systems, in-memory virtual file systems, or custom backends by simply providing a different FileSystemHost implementation.
More flexible than tools that are tightly coupled to the file system (like raw Compiler API), and enables testing and browser-based scenarios that would be impossible with direct file system access.
project-wide compiler configuration and diagnostics
Medium confidenceManages TypeScript compiler options and project configuration through a Project class that can load tsconfig.json files, apply custom compiler options, and expose diagnostic information. Provides methods like getPreEmitDiagnostics() and getCompilerOptions() to access compiler configuration and error/warning information. Supports multiple source files within a single project context, enabling whole-project analysis and refactoring that respects compiler settings like strict mode, target version, and module resolution.
Provides a high-level Project API that manages TypeScript compiler configuration and diagnostics, abstracting away the complexity of initializing the Compiler API with correct options. Automatically loads and applies tsconfig.json settings, whereas raw Compiler API requires manual configuration parsing.
Simpler than raw Compiler API for project-level configuration, and provides integrated diagnostics reporting, whereas alternatives like tsc require separate invocations to get error information.
decorator and jsdoc annotation analysis and generation
Medium confidenceProvides specialized APIs for analyzing and generating TypeScript decorators and JSDoc comments through Decorator and JSDocTag classes. Supports reading decorator arguments, generating new decorators with parameters, and parsing/generating JSDoc tags (param, returns, deprecated, etc.). Integrates with the declaration modification system to allow adding decorators and JSDoc to classes, methods, and properties programmatically.
Provides dedicated Decorator and JSDocTag classes that parse and generate decorator and JSDoc syntax, enabling programmatic manipulation of metadata annotations. Integrates with the declaration API to allow adding decorators and JSDoc when creating or modifying declarations.
More ergonomic than raw Compiler API for decorator/JSDoc manipulation, and provides structured access to decorator arguments and JSDoc tags rather than requiring manual string parsing.
multi-file batch refactoring with consistency checking
Medium confidenceEnables refactoring operations across multiple source files within a project context, maintaining consistency through symbol resolution and type checking. Supports operations like renaming symbols across files, moving declarations between files, and updating all references automatically. Uses the TypeChecker to ensure that refactoring operations respect type safety and don't break module boundaries or create circular dependencies.
Enables multi-file refactoring operations that maintain consistency through TypeChecker-based symbol resolution, ensuring that renaming or moving declarations updates all references correctly. This requires full project context, unlike file-by-file refactoring tools.
Provides type-aware refactoring that respects module boundaries and type safety, whereas simple text-based refactoring tools (like sed or regex) can break code by missing context-dependent references.
source file creation and template-based code generation
Medium confidenceProvides APIs for creating new source files within a project and populating them with code using the structure-based generation system. Supports creating files with initial content (classes, interfaces, functions) through addSourceFileAtPath() and createSourceFile() methods that accept structure objects. Enables template-based code generation where developers define the structure of generated code declaratively rather than building AST nodes manually.
Integrates file creation with the structure-based code generation system, allowing developers to create new files with full type-safe content generation in a single operation. Abstracts away the complexity of manually constructing SourceFile nodes and populating them with declarations.
More ergonomic than raw Compiler API for file creation, and maintains type safety throughout the generation process, unlike template-based generators which produce strings that must be parsed separately.
Capabilities are decomposed by AI analysis. Each maps to specific user intents and improves with match feedback.
Related Artifactssharing capabilities
Artifacts that share capabilities with ts-morph, ranked by overlap. Discovered automatically through the match graph.
javaparser
Java 1-25 Parser and Abstract Syntax Tree for Java with advanced analysis functionalities.
Google: Gemini 2.0 Flash
Gemini Flash 2.0 offers a significantly faster time to first token (TTFT) compared to [Gemini Flash 1.5](/google/gemini-flash-1.5), while maintaining quality on par with larger models like [Gemini Pro 1.5](/google/gemini-pro-1.5). It...
Mutable AI
AI agent for accelerated software development.
Mutable
AI-generated, up-to-date wiki for your...
Kilo Code
Open-source AI coding assistant for VS Code, JetBrains, and the CLI. [#opensource](https://github.com/Kilo-Org/kilocode)
Semgrep
** - Enable AI agents to secure code with [Semgrep](https://semgrep.dev/).
Best For
- ✓code generation tools and scaffolders
- ✓automated refactoring engines
- ✓linters and static analysis tools that modify code
- ✓teams building custom TypeScript transformers
- ✓static analysis tool builders
- ✓code search and refactoring tools
- ✓IDE plugin developers
- ✓teams building custom linters
Known Limitations
- ⚠All changes held in memory until explicit save — can cause memory pressure on very large codebases (100k+ files)
- ⚠No built-in transaction rollback — must manually track state if reverting changes
- ⚠Changes are not persisted to disk until saveSourceFile() is called, so process crashes lose all edits
- ⚠TypeChecker-based semantic queries require full project context — cannot analyze isolated files without tsconfig.json
- ⚠Performance degrades on large codebases (10k+ files) due to full type checking overhead
- ⚠Symbol resolution requires all dependencies to be resolvable — missing node_modules breaks semantic analysis
Requirements
Input / Output
UnfragileRank
UnfragileRank is computed from adoption signals, documentation quality, ecosystem connectivity, match graph feedback, and freshness. No artifact can pay for a higher rank.
Repository Details
Last commit: Apr 12, 2026
About
TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Categories
Alternatives to ts-morph
Are you the builder of ts-morph?
Claim this artifact to get a verified badge, access match analytics, see which intents users search for, and manage your listing.
Get the weekly brief
New tools, rising stars, and what's actually worth your time. No spam.
Data Sources
Looking for something else?
Search →