Skip to content
TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/ISSUE_TEMPLATE chore: Rename library. Feb 2, 2019
lib chore: Update declaration file. Mar 3, 2019
scripts chore: Fix code verification. Mar 3, 2019
src fix: #560 - Type#isEnum() and isEnumLiteral() would not always return… Mar 3, 2019
.travis.yml chore: Add travis-wait to building the declaration files. Dec 2, 2018 chore(release): 1.3.0 Mar 3, 2019 chore: Add code of conduct. Oct 28, 2018
LICENSE chore: Update license year. Jan 6, 2019 chore: Rename library. Feb 2, 2019
mocha.opts chore: Increase mocha timeout because of a slow CI. Aug 11, 2018
package.json chore(release): 1.0.0 Feb 2, 2019
tsconfig.declarations.json feat: #456 - Relax ts dependency to 3.0.1 and 3.0.3. Oct 6, 2018
tsconfig.json feat: #456 - Relax ts dependency to 3.0.1 and 3.0.3. Oct 6, 2018
tsconfig.scripts.json feat: #383 - Update to TS 3.0 Aug 6, 2018
tslint.json feat: Wrap JSDocFunctionType. Feb 21, 2019


npm version Build Status Coverage Status stable

TypeScript Compiler API wrapper. Provides a simple way to navigate and manipulate TypeScript and JavaScript code.

Formerly ts-simple-ast.

Library Development - Progress Update (02 February 2019)

The library has been renamed from ts-simple-ast to ts-morph. The version was also reset back to 1.0.0 with this change.

View information on breaking changes in

This library is still under early active development. Most common code manipulation/generation use cases are implemented, but there's still a lot of work to do.

Please open an issue if you find a feature missing or bug that isn't in the issue tracker.


View a generated report on what nodes have been wrapped in the file.


Work in progress:

Getting Started

  1. Installing
  2. Instantiating
  3. Adding source files
  4. Getting source files
  5. Navigating
  6. Manipulating


import { Project } from "ts-morph";

// initialize
const project = new Project({
    // Optionally specify compiler options, tsconfig.json, virtual file system, and more here.
    // If you initialize with a tsconfig.json, then it will automatically populate the project
    // with the associated source files.
    // Read more:

// add source files
const myClassFile = project.createSourceFile("src/MyClass.ts", "export class MyClass {}");
const myEnumFile = project.createSourceFile("src/MyEnum.ts", {
    enums: [{
        name: "MyEnum",
        isExported: true,
        members: [{ name: "member" }]

// get information from ast
const myClass = myClassFile.getClassOrThrow("MyClass");
myClass.getName();          // returns: "MyClass"
myClass.hasExportKeyword(); // returns: true
myClass.isDefaultExport();  // returns: false

// manipulate ast
const myInterface = myClassFile.addInterface({
    name: "IMyInterface",
    isExported: true,
    properties: [{
        name: "myProp",
        type: "number"

    name: "myProp",
    initializer: "5"


// asynchronously save all the changes above;

// get underlying compiler node from the typescript AST from any node
const compilerNode = myClassFile.compilerNode;

Or navigate existing compiler nodes created with the TypeScript compiler (the ts named export is the TypeScript compiler):

import { createWrappedNode, ClassDeclaration, ts } from "ts-morph";

// some code that creates a class declaration using the ts object
const classNode: ts.ClassDeclaration = ...;

// create and use a wrapped node
const classDec = createWrappedNode(classNode) as ClassDeclaration;
const firstProperty = classDec.getProperties()[0];

// ... do more stuff here ...


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.