Why Go for TypeScript compiler?
How to run TypeScript compiler within a website
How to watch and compile all TypeScript sources?
TypeScript compiler is being ported to Go : ProgrammingLanguages
Videos
The typescript compiler is written in Typescript, so you can load the compiler (typescript.js) into your browser. But bare in mind that it is slightly heavy (roughly 250 KB).
There's some documentation on the TS Compiler API and there's also typestring - a wrapper that is still intended for use in NodeJS, but you can use it as a starting point.
Create a file named tsconfig.json in your project root and include following lines in it:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"module": "commonjs",
"target": "ES5",
"outDir": "ts-built",
"rootDir": "src"
}
}
Please note that outDir should be the path of the directory to receive compiled JS files, and rootDir should be the path of the directory containing your source (.ts) files.
Open a terminal and run tsc -w, it'll compile any .ts file in src directory into .js and store them in ts-built directory.
The other answers may have been useful years ago, but they are now out of date.
Given that a project has a tsconfig file, run this command...
tsc --watch
... to watch for changed files and compile as needed. The documentation explains:
Run the compiler in watch mode. Watch input files and trigger recompilation on changes. The implementation of watching files and directories can be configured using environment variable. See configuring watch for more details.
To answer the original question, recursive directory watching is possible even on platforms that don't have native support, as explained by the Configuring Watch docs:
The watching of directory on platforms that don’t support recursive directory watching natively in node, is supported through recursively creating directory watcher for the child directories using different options selected by TSC_WATCHDIRECTORY