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

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

Build Options

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

Target & Module Options

--target
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
--module
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
--lib
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

--outFile
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.
--outDir
string
Specify an output folder for all emitted files.
--declaration
boolean
default:"false"
Generate .d.ts files from TypeScript and JavaScript files in your project.Aliases: -d
--declarationMap
boolean
default:"false"
Create sourcemaps for d.ts files.
--sourceMap
boolean
default:"false"
Create source map files for emitted JavaScript files.
--removeComments
boolean
default:"false"
Disable emitting comments.
--noEmit
boolean
default:"false"
Disable emitting files from a compilation.
--emitDeclarationOnly
boolean
default:"false"
Only output d.ts files and not JavaScript files.

Type Checking Options

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

Diagnostic Options

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

Help & Version

--help
boolean
default:"false"
Print this help message.Aliases: -h, -?
--version
boolean
default:"false"
Print the compiler’s version.Aliases: -v
--all
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

0
success
Compilation succeeded with no errors.
1
error
Compilation failed with type errors.
2
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.