Skip to content

Running TypeScript Natively

You can write code that's valid TypeScript directly in Node.js without the need to transpile it first.

If you are using v22.18.0 or later and your source code contains only erasable TypeScript syntax, you can execute TypeScript code without any flags.

If you are using a version less than v22.18.0, you can use the --experimental-strip-types flag to run TypeScript files directly in Node.js.

And that's it! You can now run TypeScript code directly in Node.js without the need to transpile it first, and use TypeScript to catch type-related errors.

You can disable it via --no-experimental-strip-types flag if needed.

In v22.7.0 the flag --experimental-transform-types was added to enable TypeScript-only syntax that requires transformation, like enums and namespace. Enabling --experimental-transform-types automatically implies that --experimental-strip-types is enabled, so there's no need to use both flags in the same command:

This flag is opt-in, and you should only use it if your code requires it.

What is Type Stripping?

Type stripping is the mechanism Node.js uses to run certain TypeScript files directly. Instead of compiling TypeScript into JavaScript, Node.js removes type annotations before execution. The runtime behaviour of the program remains unchanged — only TypeScript-specific syntax is erased.

This differs from traditional transpilation, which may transform syntax, change language targets, or introduce runtime helpers. Type stripping performs none of that — it only removes types, leaving your code otherwise identical.

Because type stripping does not perform type checking, it is recommended to run the TypeScript compiler separately (for example using tsc --noEmit) during development or CI to detect type errors.

Version Support

FeatureMinimum Node.js version
--experimental-strip-types flagv22.6.0
--experimental-transform-types flagv22.7.0
Type stripping without flags (v22 LTS)v22.18.0
Type stripping enabled by defaultv23.6.0

Constraints

The support for TypeScript in Node.js has some constraints to keep in mind:

  • No type checking — Node.js does not validate types at runtime. Use tsc --noEmit to detect type errors.
  • No JSX or TSX support.jsx and .tsx files are not supported natively.
  • No paths resolution — module path aliases defined in tsconfig.json are not resolved.
  • Declaration files cannot be executed.d.ts files are not runnable.
  • Some syntax requires transformation — features such as enums and namespaces require the --experimental-transform-types flag.

You can get more information on the API docs.

Configuration

The Node.js TypeScript loader (Amaro) does not need or use tsconfig.json to run TypeScript code.

We recommend configuring your editor and tsc to reflect Node.js behavior by creating a tsconfig.json using the compilerOptions listed here, as well as using TypeScript version 5.7 or higher.