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 just run directly without any flag.

node example.ts

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.

node --experimental-strip-types example.ts

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.

node --no-experimental-strip-types example.ts

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:

node --experimental-transform-types another-example.ts

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

Constraints

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

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.

Important notes

Thanks to all the contributors who have made this feature possible. This feature has been marked as stable in Node.js v25.2.0 and soon in all LTS lines. If this feature doesn't suit your use-case, please use something else or contribute a fix. Bug reports are also welcome. Please keep in mind the project is run by volunteers, without warranty of any kind, so please be patient if you can't contribute the fix yourself.

Temps de Lecture
1 min
Auteurs
Contribuer
Éditer cette page
Table des matières
  1. Constraints
  2. Configuration
  3. Important notes