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.
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.
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.
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
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
-pand file names fails with error TS5042, because file names mean "ignore the config". - If the path or config does not exist,
tscreports 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 rantscfrom.
Usage notes
- Inherit with
extends. Put shared options intsconfig.base.jsonand 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 usestsconfig.build.json, which excludes them. - Compare with
--build.tsc -pcompiles one project;tsc --buildalso builds the projects it references. - Name matters to editors. Editors discover files named
tsconfig.json(andjsconfig.json); a custom name is for command-line use. - Preview the result first with
tsc -p x --showConfig.
Related
- tsc
- tsc --build
- extends
- Tutorial: tsconfig, Large projects