TypeScript Reference ยท The tsc Command Line
Running TypeScript directly
Compare ways to run TypeScript without a separate build step: Node's built-in type stripping, tsx, ts-node and Bun or Deno, and what each one checks.
You do not always need tsc to produce JavaScript before running code. Several tools run .ts files directly, which is handy for scripts, tools and quick experiments. They differ in an important way: most of them remove types without checking them. Running the code and checking the types are two separate jobs.
node script.ts # Node 24: built-in type stripping npx tsx script.ts # esbuild-based runner npx ts-node script.ts # older, checks types by default
Try it
This site runs your TypeScript in two steps: type check with the compiler, then run on Node. The example shows the kind of code that works the same everywhere.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
The next example is a type error. A runner that only strips types would print NaN, but the checker refuses it.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
| Tool | How it works | Type checking |
|---|---|---|
node file.ts (Node 24) |
Strips type annotations; no transformation. | None |
tsx |
Transpiles with esbuild; handles tsconfig paths and JSX. |
None |
ts-node |
Compiles with the TypeScript API on load. | Yes by default; --transpile-only turns it off |
| Bun, Deno | Run TypeScript natively. | Deno can check with deno check; Bun does not |
Constraints of Node's stripping: only erasable syntax works. Enums, namespaces that contain values, parameter properties and legacy import = require() are rejected, because they need code generation. Imports must name the real file, with the .ts extension, and type-only imports must use import type or inline type. Node ignores tsconfig.json entirely.
Usage notes
- Pair running with checking: use the runner for speed and
tsc --noEmit(maybe in watch mode) for correctness. - Match the compiler options to Node:
erasableSyntaxOnly,verbatimModuleSyntaxandallowImportingTsExtensionsmake the checker enforce the same limits as Node's stripping. tsxis convenient for scripts that need path aliases, JSX or CommonJS and ESM mixing.ts-nodeis mostly legacy. It can be slow and ESM support is fiddly; most new setups choose Node's stripping ortsx.- Production: compile to JavaScript for libraries and deployed apps. Running
.tsis fine for scripts, tests and tooling. - Files under
node_modulesare not stripped by Node, so published packages must ship JavaScript.