LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

tsc

TypeScript to JavaScript compiler

TLDR

Compile a TypeScript file to JavaScript
$ tsc [file.ts]
copy
Compile using a tsconfig.json configuration
$ tsc -p [tsconfig.json]
copy
Compile in watch mode (recompile on changes)
$ tsc -w
copy
Compile with strict mode enabled
$ tsc --strict [file.ts]
copy
Compile to a specific ECMAScript target
$ tsc --target [ES2020] [file.ts]
copy
Output to a specific directory
$ tsc --outDir [dist] [file.ts]
copy
Generate source maps
$ tsc --sourceMap [file.ts]
copy
Initialize a new tsconfig.json
$ tsc --init
copy

SYNOPSIS

tsc [options] [file...]

DESCRIPTION

tsc is the TypeScript compiler that transforms TypeScript (.ts, .tsx) files into JavaScript (.js). Developed by Microsoft, TypeScript is a superset of JavaScript that adds optional static typing and modern language features.When run without arguments in a directory with tsconfig.json, tsc compiles the project according to that configuration. When files are specified on the command line, tsconfig.json is ignored unless -p is used.The compiler performs type checking to catch errors during development, then emits valid JavaScript. The --strict flag enables comprehensive type checking including strict null checks and no implicit any.Watch mode (-w) monitors source files and recompiles automatically when changes are detected, enabling a fast development workflow.

PARAMETERS

-p, --project path

Compile project from tsconfig.json at path
-w, --watch
Watch input files and recompile on changes
-t, --target version
ECMAScript target version (ES5, ES2015, ES2020, ES2022, ESNext)
--outDir directory
Redirect output to specified directory
--outFile file
Concatenate and emit output to single file
--strict
Enable all strict type-checking options
--noEmit
Do not emit outputs; type-check only
--sourceMap
Generate corresponding .map source map files
--declaration
Generate .d.ts declaration files
--module system
Module system: commonjs, es2015, es2020, esnext, node16, nodenext
--moduleResolution strategy
Module resolution strategy: node, nodenext, bundler
--incremental
Enable incremental compilation for faster rebuilds
--skipLibCheck
Skip type checking of declaration files
--esModuleInterop
Enable interoperability between CommonJS and ES Modules
--resolveJsonModule
Allow importing .json files
--jsx mode
JSX handling: react, react-jsx, react-jsxdev, preserve
--lib libs
Specify library files to include (e.g., ES2020, DOM, ES2020.Promise)
--noEmitOnError
Do not emit outputs if any errors are reported
--init
Initialize a tsconfig.json file
--listFiles
Print names of files that are part of the compilation
--showConfig
Print the final resolved configuration instead of compiling
-h, --help
Show help
-v, --version
Show version

CAVEATS

tsc requires Node.js and is typically installed via npm (npm install -g typescript). Compilation options on the command line override tsconfig.json settings. When files are specified on the command line, tsconfig.json is ignored (use -p to use a config file). Large projects may have slow compile times; consider using --incremental or --noEmit for type-check-only workflows.

HISTORY

TypeScript was developed by Microsoft under the lead of Anders Hejlsberg (creator of C# and Turbo Pascal). It was first publicly released in October 2012. The language was designed to address the challenges of large-scale JavaScript development by adding optional static types while maintaining full compatibility with existing JavaScript.

SEE ALSO

node(1), npm(1), ts-node(1), esbuild(1), swc(1), webpack(1), babel(1)

Copied to clipboard
Kai