Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท The tsc Command Line

tsc -p and --project

Reference for tsc -p and --project: pointing the compiler at a specific tsconfig file or folder, using several configs in one repo, and why it excludes file names.

tsc -p (long form --project) tells the compiler which project to compile. The argument is either a path to a configuration file or a folder that contains a file named tsconfig.json.

You need it as soon as one repository has more than one project: an app and its tests, a client and a server, or a base config plus build-specific variants such as tsconfig.build.json.

TEXT
tsc -p .
tsc -p packages/server
tsc --project tsconfig.build.json

Try it

Different projects often use different settings, but they compile the same shared modules. The code below is checked here under one config only, yet it is the kind of file every project in a repo would compile.

TypeScript A shared module compiled by every project

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.

TypeScript Indexing is unchecked unless a project opts in

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 -p <path>
tsc --project <path>
Name Description
path A .json config file, or a folder. A folder means <folder>/tsconfig.json.

Errors and edge cases:

  • Giving both -p and file names fails with error TS5042, because file names mean "ignore the config".
  • If the path or config does not exist, tsc reports an error and exits with a non-zero exit code.
  • Relative paths inside the config (include, outDir, extends) are resolved against the config file's folder, not the folder you ran tsc from.

Usage notes

  • Inherit with extends. Put shared options in tsconfig.base.json and let each project extend it; select one with -p.
  • Separate build and editor configs. The editor uses tsconfig.json, which includes tests; the release build uses tsconfig.build.json, which excludes them.
  • Compare with --build. tsc -p compiles one project; tsc --build also builds the projects it references.
  • Name matters to editors. Editors discover files named tsconfig.json (and jsconfig.json); a custom name is for command-line use.
  • Preview the result first with tsc -p x --showConfig.