The TypeScript Compiler (tsc)
The TypeScript compiler, called `tsc`, is the tool that turns your .ts files into plain JavaScript. It reads your code, checks the types, reports any errors, and then emits .js output files.
You can compile a single file directly, or set up a project with a configuration file so `tsc` knows exactly which files to include and how to compile them.
tsc app.ts
tsc app.ts --watchCompiling a single file
Running `tsc app.ts` compiles app.ts into app.js in the same folder. If there are type errors, tsc prints them to the terminal but still creates the JavaScript file by default.
Watch mode
Adding the `--watch` flag makes tsc keep running and automatically recompile whenever you save a file, which is very useful during development.
tsc app.tsapp.js createdCompiles app.ts into a plain JavaScript file named app.js.
node app.jsHello, World!Runs the compiled JavaScript file with Node.js.
Key points
- `tsc` is the official TypeScript compiler.
- It converts .ts files into .js files.
- Type errors are reported, but JavaScript output is still produced by default.
- `tsc --watch` recompiles automatically on file changes.
