9

I have a project written in TypeScript and I use a task runner for building (whatever: Gulp, Jake, etc.). The TypeScript compiler i use is the one I installed from NPM:

npm install typescript

Important: As you can see there is no global -g parameter and this is on purpose. As I need to use a specific version of the compiler with some modifications.

Calling tsc programmatically

So I want to invoke the compiler from my Javascript file configuring my task manager:

var tsc = require("typescript");

function compile() {
  tsc.compile(...); // I would like to do something like this
}

Can I do that? I have tried, but not getting much luck so far.

Andry
  • 16,172
  • 27
  • 138
  • 246

1 Answers1

6

You sure can. There are numerous tools - tsify, ts-node, ts-loader - that are built using the TypeScript Compiler API.

However, it's a little bit more complicated than a single compile call.

cartant
  • 57,105
  • 17
  • 163
  • 197