ts-morph

dsherretMIT活跃维护

把 TypeScript 编译器 API 封装成更好用的接口,方便做静态分析和用代码批量修改 TypeScript 源码。

TypeScript Compiler API wrapper for static analysis and programmatic code changes.

28.0.0发布于 2026-04-12 18:02 UTC6,224star249fork同步于 2026-11-10 11:34 UTC

怎么上手

由 README 提炼,执行前请确认
npm install ts-morph
硬件要求按 README 说明

README 未说明

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

TypeScript Compiler API 的封装库,让程序化导航和修改 TS/JS 代码更简单

把 TypeScript 编译器 API 封装成更好用的接口,方便做静态分析和用代码批量修改 TypeScript 源码。

核心能力

  • 封装 TypeScript Compiler API,简化 AST 操作
  • 支持程序化导航 TypeScript 与 JavaScript 代码
  • 支持以编程方式修改代码
  • 提供 @ts-morph/bootstrap 快速接入 Compiler API

容易踩的坑

README 未说明具体依赖版本要求;@ts-morph/bootstrap 是独立包,需单独安装

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本28.0.0
  1. 28.0.0最新正式版2026-04-12 · 2026-04-12 18:02 UTC

    What's Changed

    Note there are some breaking changes due to TypeScript 6.0. Read more here: https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/

    As part of this release, structures can now be printed to a string using the printStructure function.

    import { printStructure, StructureKind } from "ts-morph";
    
    const code = printStructure({
      kind: StructureKind.Class,
      name: "MyClass",
      isExported: true,
      properties: [{ name: "myProp", type: "string" }],
      methods: [{
        name: "myMethod",
        parameters: [{ name: "param", type: "number" }],
        returnType: "void",
      }],
    });
    console.log(code);
    

    Outputs:

    export class MyClass {
      myProp: string;
    
      myMethod(param: number): void {
      }
    }
    

    New Contributors

    Full Changelog: https://github.com/dsherret/ts-morph/compare/27.0.2...28.0.0

  2. 27.0.22025-10-12 · 2025-10-12 14:54 UTC
    查看更新说明

    What's Changed

    Full Changelog: https://github.com/dsherret/ts-morph/compare/27.0.1...27.0.2

  3. 27.0.12025-09-17 · 2025-09-17 19:24 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/dsherret/ts-morph/compare/27.0.0...27.0.1

  4. 27.0.02025-09-07 · 2025-09-07 20:47 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/dsherret/ts-morph/compare/26.0.0...27.0.0

  5. 26.0.02025-05-19 · 2025-05-19 19:08 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/dsherret/ts-morph/compare/25.0.1...26.0.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CI

    Monorepo for ts-morph and related projects.

    Packages

    • ts-morph - TypeScript Compiler API wrapper. Provides an easier way to programmatically navigate and manipulate TypeScript and JavaScript code.
    • @ts-morph/bootstrap - Separate library for getting quickly setup with the Compiler API.

    Resources