VoY VoY - 4 months ago 5
Javascript Question

How to watch and compile all TypeScript sources?

I'm trying to convert a pet project to TypeScript and don't seem to be able to use the

tsc
utility to watch and compile my files. The help says I should use the
-w
switch, but it looks like it can't watch and compile all
*.ts
files in the some directory recursively. This seems like something
tsc
should be able to handle. What are my options?

Answer

Technically speaking you have a few options here:

If you are using an IDE like Sublime Text and integrated MSN plugin for Typescript: http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx you can create a build system which compile the .ts source to .js automatically. Here is the explanation how you can do it: How to configure a Sublime Build System for TypeScript.

You can define even to compile the source code to destination .js file on file save. There is a sublime package hosted on github: https://github.com/alexnj/SublimeOnSaveBuild which make this happen, only you need to include the ts extension in the SublimeOnSaveBuild.sublime-settings file.

Another possibility would be to compile each file in the command line. You can compile even multiple files at once by separating them with spaces like so: tsc foo.ts bar.ts. Check this thread: How can I pass multiple source files to the TypeScript compiler?, but i think the first option is more handy.

Comments