tsc
Output time stamp counter value
TLDR
Compile a TypeScript file foobar.ts into a JavaScript file foobar.js
Compile a TypeScript file into JavaScript using a specific target syntax (default is ES3)
Compile a TypeScript file into a JavaScript file with a custom name
Compile all .ts files of a TypeScript project defined in a tsconfig.json file
Run the compiler using command-line options and arguments fetched from a text file
Type-check multiple JavaScript files, and output only the errors
Run the compiler in watch mode, which automatically recompiles code when it changes
SYNOPSIS
tsc [options] [file...]
PARAMETERS
--init
Creates a tsconfig.json file in the current directory with default options.
--watch, -w
Watches for file changes and recompiles automatically.
--project
Compiles the project in the specified path, or the current directory if no path is provided.
--target
Specifies the ECMAScript target version for the output JavaScript (e.g., ES5, ES2015, ESNext).
--module
Specifies the module code generation method (e.g., CommonJS, ESNext, AMD).
--outDir
Redirects output structure to the specified directory.
--outFile
Concatenates and emits output into a single file.
--rootDir
Specifies the root directory of input files.
--strict
Enables all strict type-checking options (e.g., noImplicitAny, strictNullChecks).
--noEmit
Do not emit outputs, only perform type checking.
--jsx
Specifies the JSX emit mode (e.g., preserve, react, react-jsx).
--listFiles
Prints names of files that are part of the compilation.
--version
Prints the compiler version.
--help
Prints a detailed help message with all available options.
DESCRIPTION
tsc is the TypeScript Compiler, a command-line utility that transforms TypeScript files (.ts, .tsx, .d.ts) into standard JavaScript files (.js). Developed by Microsoft, TypeScript is a superset of JavaScript, adding optional static typing and class-based object-oriented programming features. The primary purpose of tsc is to perform type-checking on TypeScript code, identify potential errors during development, and then emit runnable JavaScript code that can be executed in any JavaScript runtime environment (like browsers or Node.js).
The compiler leverages a configuration file, tsconfig.json, which dictates how the compilation process should behave, including target JavaScript version, module resolution strategy, output directories, and more. While tsc can compile individual files, it is most commonly used in projects by running tsc in the project root, allowing it to pick up the tsconfig.json file and compile the entire project. It also supports watch mode, automatically recompiling files upon changes, which is invaluable for rapid development cycles.
CAVEATS
tsc is not a native Linux command; it is part of the Node.js ecosystem and requires Node.js and npm (or yarn) to be installed first. It is typically installed globally via npm (npm install -g typescript). While powerful, performance can be a concern for very large projects without proper configuration, requiring optimization of compiler options or build tooling. Its behavior is heavily dependent on the tsconfig.json file, which must be correctly configured for project-wide compilation.
ROLE OF <B>TSCONFIG.JSON</B>
The tsconfig.json file is central to tsc's operation for projects. It's a JSON file that specifies root files and compiler options required to compile the project. When tsc is run without specifying input files, it looks for this file in the current directory and parent directories to determine compilation settings and files to include. This allows for consistent build configurations across different environments and team members.
INTEGRATION WITH BUILD TOOLS
While tsc handles compilation, it's often integrated into larger build workflows using tools like Webpack, Rollup, or Parcel. These tools can leverage tsc for type-checking and transpilation but also handle asset bundling, code splitting, and other complex build tasks, offering a more comprehensive solution for modern web applications.
HISTORY
TypeScript was first publicly released by Microsoft in October 2012. tsc has been the core compilation tool since its inception, evolving alongside the TypeScript language itself. Early versions focused on providing robust static typing and ES6 features before they were widely adopted in JavaScript. Continuous development has added support for newer ECMAScript standards, improved performance, enhanced tooling integration, and refined its type system, making TypeScript a popular choice for large-scale application development.