Command Line
_TypeScript · Reference cheat sheet_
Command Line
TypeScript · Reference cheat sheet
📖 Overview
The TypeScript compiler CLI (tsc) type-checks and optionally emits JavaScript. Install via typescript and run with npx tsc or a local node_modules binary. Most options mirror tsconfig.json compiler flags.
🧩 Core concepts
- Project mode —
tsc -p tsconfig.json(default: nearest/implicit config). - Emit vs check —
noEmit/--noEmitfor CI typecheck; omit for JS output. - Watch —
--watch/-wrebuilds on change. - Incremental —
--incremental+.tsbuildinfofor faster rebuilds. - Build mode —
tsc -bfor project references (compositeprojects). - Show config —
--showConfigprints the effective resolved config.
💡 Examples
# Install
npm install -D typescript
npx tsc --version
# Init a tsconfig
npx tsc --init
# Typecheck only (CI-friendly)
npx tsc -p tsconfig.json --noEmit
# Emit to outDir from config
npx tsc -p tsconfig.json
# Watch mode
npx tsc -p tsconfig.json --watch
# Build solution (project references)
npx tsc -b packages/utils packages/app --force
# One-off compile without relying on config paths
npx tsc src/index.ts --target ES2022 --module NodeNext --outdir dist
# Effective config
npx tsc --showConfig
# Common flags
npx tsc --strict --pretty false --listFiles falsepackage.json scripts:
{
"scripts": {
"typecheck": "tsc -p tsconfig.json --noEmit",
"build": "tsc -p tsconfig.json"
}
}⚠️ Pitfalls
- CLI flags override
tsconfigwhen both are set — know which wins for CI. - Compiling a single
.tsfile ignores most of your projectpaths/includesetup. tsc -brequirescomposite: true(and usuallydeclaration: true) on referenced projects.- Global
tscmay be an older version than the project’s local TypeScript — prefernpx/npm exec.