Compiling & Running TypeScript
7 min read
Compiling & Running TypeScript
TypeScript must be compiled to JavaScript before it runs. The tsc command reads your tsconfig.json and produces .js files in the outDir. You then run those files with Node.js as normal.
ts
// One-off compile
// npx tsc
// Watch mode — recompiles on every file save
// npx tsc --watch
// Then run the output
// node dist/index.jsFor development speed, tools like ts-node or tsx let you run TypeScript files directly without a separate compile step. Bundlers like Vite, esbuild, and Webpack handle TypeScript as part of their build pipeline.
ts
// Run directly with tsx (no separate compile step)
// npx tsx src/index.tsTypeScript errors do NOT stop tsc from emitting JavaScript by default. Add "noEmitOnError": true to your compilerOptions if you want compilation to abort on errors.
Ready to test yourself?
Practice TypeScript— quiz & coding exercises