Skip to Content
Learning TypeScript 2.x - Second Edition
book

Learning TypeScript 2.x - Second Edition

by Remo H. Jansen
April 2018
Beginner content levelBeginner
536 pages
13h 21m
English
Packt Publishing
Content preview from Learning TypeScript 2.x - Second Edition

Traversing the TypeScript AST

We have learned how to visualize the TypeScript AST using the TypeScript AST viewer online. At this point, it is normal to ask ourselves where all this information is coming from. In this section, we are going to demonstrate how to use the TypeScript compiler APIs to access the AST.

After creating a package.json file and installing TypeScript using npm, the first thing that we need to do is to create a new TypeScript file and import TypeScript as a module:

import * as ts from "typescript"; 

Then we need to declare the configuration of the TypeScript compiler using an object literal:

const options = { 
    module: ts.ModuleKind.CommonJS, 
    target: ts.ScriptTarget.ES5, 
}; 

Next, we need to create a new program:

const ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering TypeScript - Fourth Edition

Mastering TypeScript - Fourth Edition

Nathan Rozentals
Learning TypeScript

Learning TypeScript

Josh Goldberg
TypeScript for Beginners

TypeScript for Beginners

Bharath Thippireddy

Publisher Resources

ISBN: 9781788391474Supplemental Content