TypeScript Reference ยท The tsc Command Line
node --experimental-strip-types
Reference for running .ts files in Node with type stripping: the --experimental-strip-types flag, erasable syntax limits, import rules and the transform option.
Node can run TypeScript files by stripping the type annotations and executing what is left. It does not compile: it replaces types with whitespace, so line and column numbers stay the same and no source map is needed. Node does no type checking at all.
Type stripping was introduced behind the --experimental-strip-types flag. In current Node releases (including Node 24) it is on by default, so node file.ts just works, and the flag is only needed on older versions. A related flag, --experimental-transform-types, also converts a few non-erasable features.
node app.ts node --experimental-strip-types app.ts node --experimental-transform-types app.ts
Try it
The runner on this site can execute a file with Node's own type stripping. A first line // ts selects it. Erasable syntax like annotations, interfaces and generics all work.
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 process.stdin), it gets the next line from this box.
Enums need generated code, so stripping alone cannot run them.
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 process.stdin), it gets the next line from this box.
Syntax
| Flag | Description |
|---|---|
--experimental-strip-types |
Remove type syntax and run. Default-on in recent Node; may print an experimental warning. |
--no-experimental-strip-types |
Turn stripping off. |
--experimental-transform-types |
Also transform enums, namespaces and parameter properties. Supports source maps. |
Rules for files:
- Only erasable syntax: types, interfaces, generics,
as,satisfies,!,declare, and so on. - Non-erasable features (
enum,namespacewith values, constructor parameter properties,import x = require()) fail withERR_UNSUPPORTED_TYPESCRIPT_SYNTAX. - Local imports must include the extension:
import { f } from "./util.ts". - Type-only imports need
import type { T }orimport { type T }; otherwise Node looks for a runtime export that does not exist. tsconfig.jsonis ignored, includingpaths,targetandjsx; JSX is unsupported.- Files inside
node_modulesare not processed.
Usage notes
- Make the checker agree: set
erasableSyntaxOnly,verbatimModuleSyntaxandallowImportingTsExtensions(withnoEmit) sotscflags what Node would reject. - Use
.mtsand.ctsor"type": "module"inpackage.jsonto choose ESM or CommonJS like for.jsfiles. - Prefer
constobjects and unions instead of enums if you want portable code. - Check in CI with
tsc --noEmit; Node will happily run code with type errors. - Stack traces point to the original lines, because stripping preserves positions.