tsc Command Line
The tsc command transpiles TypeScript (.ts) files into JavaScript. It can be used with or without a tsconfig.json file and supports many flags for customizing the compilation process.
In a project, run it through your package manager (npx tsc, pnpm tsc) so the project's own TypeScript version is used.
Common Commands
| Command | Description |
|---|---|
tsc | Transpiles the project using tsconfig.json. |
tsc file.ts | Transpiles a single .ts file into .js (no tsconfig.json). |
tsc --watch or tsc -w | Watches files for changes and transpiles automatically. |
tsc --init | Creates a tsconfig.json with recommended settings. |
tsc --noEmit | Performs type checking without generating any .js output. |
tsc -p ./other | Uses the tsconfig.json in another folder (--project). |
tsc --version | Prints the TypeScript version. |
tsc file.ts ignores tsconfig.json. Since TypeScript 6.0, passing file names in a folder that has a tsconfig.json is reported as a mistake: run plain tsc instead.Compiler Options as Flags
Every tsconfig.json option can also be passed as a flag. Flags override the config file for that run:
| Flag | Description |
|---|---|
--outDir ./dist | Outputs transpiled .js files into the specified directory. |
--rootDir ./src | Specifies the root folder for source files. |
--target ES2022 | Sets the ECMAScript target version (Ex: ES2015, ES2022). |
--module nodenext | Sets the module system (nodenext, esnext, commonjs). |
--strict | Enables all strict type-checking options. |
--declaration | Also writes .d.ts type declaration files. |
--sourceMap | Writes .js.map files for debugging the original .ts. |
Type Checking Only
Many projects let another tool (Vite, esbuild, Node.js type stripping) turn TypeScript into JavaScript, because it's faster. tsc is then used only to check types, usually in CI and before commits:
{
"scripts": {
"typecheck": "tsc --noEmit"
}
}
Utility Types
TypeScript ships with generic types that transform other types. They save you from writing the same shape twice.
tsconfig.json
tsconfig.json is a configuration file used by the TypeScript compiler to understand how to transpile your code. Its folder is the root of the project: running tsc there compiles the files it describes.
