tsc CLI

Compile files

Start with one file. Pass the file name to tsc and it writes JavaScript next to the source. Open the emitted file once so the mapping from TypeScript to JavaScript feels concrete.

A clean compile prints nothing. Errors print with file name, line, and column, so read the first error and fix from the top down.

tsc app.ts

no output means success, app.js is written

function add(a: number, b: number): number { return a + b; } const total = add(2, 3); console.log(total);

Watch mode

Watch mode keeps tsc running and recompiles on every save. It is the tight feedback loop you want while learning and while building a small feature.

Leave the terminal visible beside the editor. When an error appears, fix it, save again, and confirm that the watcher goes quiet.

tsc --watch

Watching for file changes

Use a project

A project file named tsconfig.json stores shared settings for the whole folder. Point tsc at the project and it compiles every included file with the same rules.

This is how real codebases keep builds consistent. One developer command builds the same output on every machine.

tsc --project tsconfig.json

build uses settings from tsconfig.json

Check without emitting

Sometimes you only want answers, not files. Ask tsc to type check and skip emit entirely. Nothing is written, so the folder stays clean.

Editors run the same check in the background, so the command line and the editor agree. Run it before a commit to catch what tired eyes miss.

tsc --noEmit

no errors found

Next: tsconfig deep dive

Article author: Arthur Isaev

Banner image