Skip to main content
The tsc command is the TypeScript compiler that compiles TypeScript files to JavaScript.

Installation

Basic Usage

Command-Line Options

Project Configuration

string
default:"tsconfig.json"
Compile the project given the path to its configuration file, or to a folder with a tsconfig.json.Aliases: -p
boolean
default:"false"
Initializes a TypeScript project and creates a tsconfig.json file.
boolean
default:"false"
Print the final configuration instead of building.

Build Options

boolean
default:"false"
Build one or more projects and their dependencies, if out of date.Aliases: -b
boolean
default:"false"
Watch input files and trigger recompilation on changes.Aliases: -w
boolean
default:"false"
Save .tsbuildinfo files to allow for incremental compilation of projects.Aliases: -i

Target & Module Options

string
default:"ES3"
Set the JavaScript language version for emitted JavaScript and include compatible library declarations.Aliases: -tValid values: ES3, ES5, ES6/ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ES2023, ES2024, ES2025, ESNext
string
default:"computed"
Specify what module code is generated.Aliases: -mValid values: CommonJS, AMD, UMD, System, ES6/ES2015, ES2020, ES2022, ESNext, Node16, Node18, Node20, NodeNext, Preserve
string[]
Specify a set of bundled library declaration files that describe the target runtime environment.Valid values: ES5, ES2015, ES2016, ES2017, ES2018, ES2019, ES2020, ES2021, ES2022, ES2023, ES2024, ES2025, ESNext, DOM, WebWorker, ScriptHost

Emit Options

string
Specify a file that bundles all outputs into one JavaScript file. If declaration is true, also designates a file that bundles all .d.ts output.
string
Specify an output folder for all emitted files.
boolean
default:"false"
Generate .d.ts files from TypeScript and JavaScript files in your project.Aliases: -d
boolean
default:"false"
Create sourcemaps for d.ts files.
boolean
default:"false"
Create source map files for emitted JavaScript files.
boolean
default:"false"
Disable emitting comments.
boolean
default:"false"
Disable emitting files from a compilation.
boolean
default:"false"
Only output d.ts files and not JavaScript files.

Type Checking Options

boolean
default:"true"
Enable all strict type-checking options.
boolean
default:"true if strict"
Enable error reporting for expressions and declarations with an implied ‘any’ type.
boolean
default:"true if strict"
When type checking, take into account null and undefined.
boolean
default:"true if strict"
When assigning functions, check to ensure parameters and the return values are subtype-compatible.

Diagnostic Options

boolean
default:"true"
Enable color and formatting in TypeScript’s output to make compiler errors easier to read.
boolean
default:"false"
Output compiler performance information after building.
boolean
default:"false"
Output more detailed compiler performance information after building.
boolean
default:"false"
Print all of the files read during the compilation.
boolean
default:"false"
Print files read during the compilation including why it was included.
boolean
default:"false"
Log paths used during the moduleResolution process.

Help & Version

boolean
default:"false"
Print this help message.Aliases: -h, -?
boolean
default:"false"
Print the compiler’s version.Aliases: -v
boolean
default:"false"
Show all compiler options.

Real-World Examples

Basic Compilation

Compile a TypeScript file to JavaScript:
Output:

Development Build

Compile with source maps and watch mode for development:
Output:

Production Build

Compile for production with optimizations:
Output:

Type Checking Only

Check types without emitting files:
Output:

Project References

Build a project with references:
Output:

Exit Codes

success
Compilation succeeded with no errors.
error
Compilation failed with type errors.
error
Invalid command-line arguments.

Performance Tips

Use --incremental to speed up subsequent builds by saving compilation information.
Use --skipLibCheck to skip type checking of declaration files and speed up compilation.
Use project references with --build for large monorepo projects to enable incremental builds.

Common Errors

error TS5023: Unknown compiler option ‘xxx’Check the option name for typos. Use tsc --help to see all available options.
error TS5057: Cannot find a tsconfig.json file at the specified directoryEnsure tsconfig.json exists in the specified directory or use tsc --init to create one.

Source Code Reference

The TypeScript compiler implementation:
The tsc binary (bin/tsc) is a wrapper that loads the compiled compiler from lib/tsc.js.