Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท The tsc Command Line

The tsc command

Reference for the tsc command: how it finds tsconfig.json, how files versus projects are compiled, what it prints and emits, and the options you reach for daily.

tsc is the TypeScript compiler's command-line program. It reads your source files, checks their types, and (unless told otherwise) writes JavaScript, declaration files and source maps. In TypeScript 7 the compiler is a native executable, so the same command is much faster on large projects, and its options and messages stay the same as in earlier versions.

tsc runs in one of two modes. With file names on the command line it compiles just those files and ignores tsconfig.json. With no file names it searches for tsconfig.json in the current folder and then in each parent folder, and compiles the project that file describes.

TEXT
tsc                      # use the nearest tsconfig.json
tsc main.ts              # compile one file, ignore tsconfig.json
tsc --noEmit             # check only, write nothing
tsc -p ./packages/app    # use another project

Try it

Every example on this site is compiled by TypeScript with --strict before it runs. A clean program prints its output.

TypeScript A program that compiles cleanly

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

When the compiler finds a problem it prints a diagnostic in the form file(line,column): error TSxxxx: message. This is the same text tsc shows in a terminal when it is not colorizing.

TypeScript What a diagnostic looks like

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TEXT
tsc [options] [file ...]
Name Description
file ... Source files to compile. If you pass any, tsconfig.json is ignored (and -p cannot be combined with them).
-p, --project A tsconfig file or a folder containing one. See tsc -p.
--noEmit Type-check only. See tsc --noEmit.
-w, --watch Stay running and recompile on change.
-b, --build Build project references in order.
--init Create a tsconfig.json.

Output: nothing is printed on success. Errors go to standard output, one diagnostic per message, and the process sets an exit code.

Edge cases: options on the command line override the same options in tsconfig.json. If no tsconfig.json is found and no files are given, tsc prints its help text instead of compiling anything.

Usage notes

  • File mode ignores your config. Running tsc main.ts inside a project uses default options, not your strict or target settings. This is the most common surprise; use tsc -p . or plain tsc for project settings.
  • Errors do not stop emit by default. JavaScript is still written unless noEmitOnError is on. In build pipelines either set it or run tsc --noEmit as a separate check.
  • Use it as a checker, not only a compiler. Many projects let a bundler or Node produce the JavaScript and run tsc --noEmit in CI.
  • Install it per project. npm install --save-dev typescript and run it through npx tsc or an npm script, so every developer uses the same version.
  • Related commands: options are listed by tsc --help and the version by tsc --version.