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

CommandDescription
tscTranspiles the project using tsconfig.json.
tsc file.tsTranspiles a single .ts file into .js (no tsconfig.json).
tsc --watch or tsc -wWatches files for changes and transpiles automatically.
tsc --initCreates a tsconfig.json with recommended settings.
tsc --noEmitPerforms type checking without generating any .js output.
tsc -p ./otherUses the tsconfig.json in another folder (--project).
tsc --versionPrints 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:

FlagDescription
--outDir ./distOutputs transpiled .js files into the specified directory.
--rootDir ./srcSpecifies the root folder for source files.
--target ES2022Sets the ECMAScript target version (Ex: ES2015, ES2022).
--module nodenextSets the module system (nodenext, esnext, commonjs).
--strictEnables all strict type-checking options.
--declarationAlso writes .d.ts type declaration files.
--sourceMapWrites .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:

package.json
{
  "scripts": {
    "typecheck": "tsc --noEmit"
  }
}