Skip to content
Tutorials Center
My learning

Topics

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.

TEXT
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.

Node.js Erasable syntax runs as is

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.

Node.js An enum is not erasable

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, namespace with values, constructor parameter properties, import x = require()) fail with ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX.
  • Local imports must include the extension: import { f } from "./util.ts".
  • Type-only imports need import type { T } or import { type T }; otherwise Node looks for a runtime export that does not exist.
  • tsconfig.json is ignored, including paths, target and jsx; JSX is unsupported.
  • Files inside node_modules are not processed.

Usage notes

  • Make the checker agree: set erasableSyntaxOnly, verbatimModuleSyntax and allowImportingTsExtensions (with noEmit) so tsc flags what Node would reject.
  • Use .mts and .cts or "type": "module" in package.json to choose ESM or CommonJS like for .js files.
  • Prefer const objects 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.