ts-morph
ts-morph is a TypeScript wrapper around the TypeScript Compiler API that simplifies programmatic code navigation and transformation. It lets developers read, analyze, and modify TypeScript and JavaScript code at scale without dealing with low-level compiler internals.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | dsherret/ts-morph |
| Owner | dsherret |
| Primary language | TypeScript |
| License | MIT — OSI-approved |
| Stars | 6.1k |
| Forks | 234 |
| Open issues | 289 |
| Latest release | 28.0.0 (2026-04-12) |
| Last updated | 2026-04-12 |
| Source | https://github.com/dsherret/ts-morph |
What ts-morph is
ts-morph abstracts the TypeScript Compiler API into a higher-level object model for AST traversal, querying, and mutation. It supports static analysis workflows, code generation, and refactoring tasks with a fluent API built on top of the official compiler.
Get the ts-morph source
Clone the repository and explore it locally.
git clone https://github.com/dsherret/ts-morph.gitcd ts-morph# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- ts-morph requires installing the TypeScript Compiler as a peer dependency; ensure version compatibility with your project's TypeScript version.
- AST manipulation requires careful understanding of the TypeScript type hierarchy; refer to official TypeScript Compiler API docs alongside ts-morph's API.
- Memory usage can be significant when loading large projects into memory; consider batching or streaming approaches for very large codebases.
- Roundtrip fidelity: verify that modified code preserves formatting, comments, and whitespace as expected for your use case.
- Test coverage of your codemod/refactoring logic is critical; AST changes can silently introduce type errors or logic bugs.
When to avoid it — and what to weigh
- Simple String Find-and-Replace Suffices — If you only need basic text substitution or regex matching, ts-morph is over-engineered. Standard text tools are faster and simpler.
- Runtime Code Evaluation Required — ts-morph is a static analysis library; it does not execute code or provide runtime introspection. For dynamic analysis, use Node.js vm or similar.
- Non-TypeScript/JavaScript Codebases — ts-morph is TypeScript Compiler API–specific. For Python, Go, Java, or other languages, use language-specific AST libraries (e.g., ast, tree-sitter).
- Extreme Performance at Scale (100k+ Files) — Unknown whether ts-morph scales efficiently to very large projects. Compiler API performance characteristics and memory usage at scale require testing.
License & commercial use
ts-morph is licensed under the MIT License, a permissive OSI-approved license that permits commercial use, modification, and distribution with minimal restrictions.
MIT License explicitly permits commercial use. You may use ts-morph in proprietary products and internal tools without license restrictions. Include a copy of the MIT license and original attribution in distributions. No warranty or liability indemnity is provided by the licensor.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Adequate |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Good |
| Assessment confidence | High |
ts-morph parses and manipulates code; no built-in input validation. Ensure source code is from trusted origins if processing untrusted inputs. No obvious injection vectors in the library itself, but arbitrary code generation or eval workflows introduce risk. Regularly update TypeScript dependency for security patches.
Alternatives to consider
babel
Industry standard for JavaScript/TypeScript AST transformation; larger ecosystem and more mature for code generation, but steeper learning curve and less TypeScript-native.
recast
Focuses on roundtrip code preservation and pretty-printing; lighter-weight but fewer high-level abstractions and less TypeScript support than ts-morph.
tree-sitter
Language-agnostic parser; faster incremental parsing and multi-language support, but requires learning a different API and lacks TypeScript Compiler semantic understanding.
Build on ts-morph with DEV.co software developers
ts-morph simplifies AST-based code transformation. Assess your project's TypeScript version, peer dependencies, and scalability needs. Consider our custom development services if you need embedded tooling or large-scale codemod infrastructure.
Talk to DEV.coRelated on DEV.co
Explore the category and the services that help you build with it.
ts-morph FAQ
Does ts-morph work with JavaScript files?
Can I use ts-morph to format code?
What is the performance for large codebases?
Is ts-morph suitable for IDE/language server plugins?
Work with a software development agency
From first prototype to production, DEV.co delivers software development services around tools like ts-morph. Our software development agency staffs experienced software developers and web developers for custom software development, web development, integrations, and ongoing support across ai coding agents and beyond.
Ready to Build TypeScript Codemods & Refactoring Tools?
ts-morph simplifies AST-based code transformation. Assess your project's TypeScript version, peer dependencies, and scalability needs. Consider our custom development services if you need embedded tooling or large-scale codemod infrastructure.