node/doc/api/typescript.md
RafaelGSS 9e633f94ce
2026-05-05, Version 26.0.0 (Current)
assert:
  * (SEMVER-MAJOR) allow printf-style messages as assertion error (Ruben Bridgewater) https://github.com/nodejs/node/pull/58849
build:
  * (SEMVER-MAJOR) bump GCC requirement to 13.2 (Michaël Zasso) https://github.com/nodejs/node/pull/62555
  * (SEMVER-MAJOR) enable Temporal by default (Richard Lau) https://github.com/nodejs/node/pull/61806
  * (SEMVER-MAJOR) enable V8_VERIFY_WRITE_BARRIERS in debug build (Joyee Cheung) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) target Power 9 for AIX/IBM i (Richard Lau) https://github.com/nodejs/node/pull/62296
  * (SEMVER-MAJOR) drop support for Python 3.9 (Mike McCready) https://github.com/nodejs/node/pull/61177
  * (SEMVER-MAJOR) enable maglev for Linux on s390x (Richard Lau) https://github.com/nodejs/node/pull/60863
  * (SEMVER-MAJOR) reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) reset embedder string to "-node.0" (Michaël Zasso) https://github.com/nodejs/node/pull/60111
build,test:
  * (CVE-2026-21717) (SEMVER-MAJOR) test array index hash collision (Joyee Cheung) https://github.com/nodejs/node/pull/61898
build,win:
  * (SEMVER-MAJOR) fix Temporal build (StefanStojanovic) https://github.com/nodejs/node/pull/61806
crypto:
  * (SEMVER-MAJOR) unify asymmetric key import through KeyObjectHandle::Init (Filip Skokan) https://github.com/nodejs/node/pull/62499
  * (SEMVER-MAJOR) runtime-deprecate DEP0203 and DEP0204 (Filip Skokan) https://github.com/nodejs/node/pull/62453
  * (SEMVER-MAJOR) decorate async crypto job errors with OpenSSL error details (Filip Skokan) https://github.com/nodejs/node/pull/62348
  * (SEMVER-MAJOR) default ML-KEM and ML-DSA pkcs8 export to seed-only format (Filip Skokan) https://github.com/nodejs/node/pull/62178
  * (SEMVER-MAJOR) move DEP0182 to End-of-Life (Tobias Nießen) https://github.com/nodejs/node/pull/61084
  * (SEMVER-MAJOR) fix DOMException name for non-extractable key error (Filip Skokan) https://github.com/nodejs/node/pull/60830
deps:
  * (SEMVER-MAJOR) V8: cherry-pick 0f024d4e66e0 (ishabi) https://github.com/nodejs/node/pull/62408
  * (SEMVER-MAJOR) fix V8 race condition for AIX (Abdirahim Musse) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick cd2c216e7658 (LuYahan) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: backport 088b7112e7ab (Igor Sheludko) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick 00f6e834029f (Joyee Cheung) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: backport bef0d9c1bc90 (Joyee Cheung) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick cf1bce40a5ef (Richard Lau) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick daf4656ba85e (Milad Fa) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick d83f479604c8 (Joyee Cheung) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick edeb0a4fa181 (Joyee Cheung) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick aa0b288f87cc (Richard Lau) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) patch V8 to fix Windows build (StefanStojanovic) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) V8: cherry-pick highway@989a498fdf3 (Richard Lau) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) support madvise(3C) across ALL illumos revisions (Dan McDonald) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) patch V8 for illumos (Dan McDonald) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) remove problematic comment from v8-internal (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) define V8_PRESERVE_MOST as no-op on Windows (Stefan Stojanovic) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) patch V8 to avoid duplicated zlib symbol (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update V8 to 14.6.202.33 (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update undici to 8.0.2 (Node.js GitHub Bot) https://github.com/nodejs/node/pull/62384
  * (SEMVER-MAJOR) V8: backport 151d0a44a1b2 (Abdirahim Musse) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) V8: cherry-pick 47800791b35c (Jakob Kummerow) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) patch V8 for illumos (Dan McDonald) https://github.com/nodejs/node/pull/59805
  * (SEMVER-MAJOR) use std::map in MSVC STL for EphemeronRememberedSet (Joyee Cheung) https://github.com/nodejs/node/pull/58070
  * (SEMVER-MAJOR) remove problematic comment from v8-internal (Michaël Zasso) https://github.com/nodejs/node/pull/58070
  * (SEMVER-MAJOR) patch V8 to avoid duplicated zlib symbol (Michaël Zasso) https://github.com/nodejs/node/pull/54077
  * (SEMVER-MAJOR) update V8 to 14.3.127.12 (Michaël Zasso) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) V8: cherry-pick ff34ae20c8e3 (Chengzhong Wu) https://github.com/nodejs/node/pull/60111
  * (SEMVER-MAJOR) V8: backport fed47445bbdd (Abdirahim Musse) https://github.com/nodejs/node/pull/60111
  * (SEMVER-MAJOR) patch V8 for illumos (Dan McDonald) https://github.com/nodejs/node/pull/59805
  * (SEMVER-MAJOR) use std::map in MSVC STL for EphemeronRememberedSet (Joyee Cheung) https://github.com/nodejs/node/pull/58070
  * (SEMVER-MAJOR) remove problematic comment from v8-internal (Michaël Zasso) https://github.com/nodejs/node/pull/58070
  * (SEMVER-MAJOR) patch V8 to avoid duplicated zlib symbol (Michaël Zasso) https://github.com/nodejs/node/pull/54077
  * (SEMVER-MAJOR) update V8 to 14.2.231.9 (Michaël Zasso) https://github.com/nodejs/node/pull/60111
diagnostics_channel:
  * (SEMVER-MAJOR) ensure tracePromise consistency with non-Promises (René) https://github.com/nodejs/node/pull/61766
doc:
  * (SEMVER-MAJOR) remove extensionless CJS exception for type:module packages (Matteo Collina) https://github.com/nodejs/node/pull/62176
  * (SEMVER-MAJOR) update supported Windows SDK version to 11 (Mike McCready) https://github.com/nodejs/node/pull/61973
  * (SEMVER-MAJOR) drop p8 and z13 support (Milad Fa) https://github.com/nodejs/node/pull/61005
http:
  * (SEMVER-MAJOR) move writeHeader to end-of-life (Sebastian Beltran) https://github.com/nodejs/node/pull/60635
  * (SEMVER-MAJOR) fix handling of HTTP upgrades with bodies (Tim Perry) https://github.com/nodejs/node/pull/60016
lib:
  * (SEMVER-MAJOR) return undefined for localStorage without file (Matteo Collina) https://github.com/nodejs/node/pull/61333
lib,src:
  * (SEMVER-MAJOR) implement QuotaExceededError as DOMException-derived interface (Filip Skokan) https://github.com/nodejs/node/pull/62293
module:
  * (SEMVER-MAJOR) runtime-deprecate module.register() (Geoffrey Booth) https://github.com/nodejs/node/pull/62401
  * (SEMVER-MAJOR) remove --experimental-transform-types (Marco Ippolito) https://github.com/nodejs/node/pull/61803
src:
  * (SEMVER-MAJOR) replace uses of deprecated v8::External APIs (gahaas) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) stop using `v8::PropertyCallbackInfo<T>::This()` (Igor Sheludko) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) avoid deprecated Wasm API (Clemens Backes) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) avoid deprecated `FixedArray::Get` (Clemens Backes) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update NODE_MODULE_VERSION to 147 (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) remove deprecated and unused isolate fields (Michaël Zasso) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) update NODE_MODULE_VERSION to 144 (Michaël Zasso) https://github.com/nodejs/node/pull/60488
  * (SEMVER-MAJOR) include `node_api_types.h` instead of `node_api.h` in `node.h` (Anna Henningsen) https://github.com/nodejs/node/pull/60496
  * (SEMVER-MAJOR) update NODE_MODULE_VERSION to 142 (Michaël Zasso) https://github.com/nodejs/node/pull/60111
stream:
  * (SEMVER-MAJOR) promote DEP0201 to runtime deprecation (René) https://github.com/nodejs/node/pull/62173
  * (SEMVER-MAJOR) move _stream_* to end-of-life (Sebastian Beltran) https://github.com/nodejs/node/pull/60657
  * (SEMVER-MAJOR) readable read one buffer at a time (Robert Nagy) https://github.com/nodejs/node/pull/60441
  * (SEMVER-MAJOR) preserve AsyncLocalStorage on finished only when needed (avcribl) https://github.com/nodejs/node/pull/59873
test:
  * (SEMVER-MAJOR) skip wasm allocation tests in workers (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update wpt Wasm jsapi expectations (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) support presence of Temporal global (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) add type tags to uses of v8::External (gahaas) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) fix test-linux-perf-logger for V8 14.3 (Michaël Zasso) https://github.com/nodejs/node/pull/60488
tools:
  * (SEMVER-MAJOR) remove v8_initializers_slow workaround from v8.gyp (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) add Rust args to `tools/make-v8.sh` (Richard Lau) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update V8 gypfiles for 14.6 (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update V8 gypfiles for 14.5 (Michaël Zasso) https://github.com/nodejs/node/pull/61898
  * (SEMVER-MAJOR) update V8 gypfiles for 14.4 (Michaël Zasso) https://github.com/nodejs/node/pull/61898
util:
  * (SEMVER-MAJOR) mark proxied objects as such when inspecting them (Ruben Bridgewater) https://github.com/nodejs/node/pull/61029
  * (SEMVER-MAJOR) reduce TextEncoder.encodeInto function size (Yagiz Nizipli) https://github.com/nodejs/node/pull/60339

PR-URL: https://github.com/nodejs/node/pull/62526
2026-05-05 11:17:12 -03:00

7.7 KiB

Modules: TypeScript

Stability: 2 - Stable

Enabling

There are two ways to enable runtime TypeScript support in Node.js:

  1. For full support of all of TypeScript's syntax and features, including using any version of TypeScript, use a third-party package.

  2. For lightweight support, you can use the built-in support for type stripping.

Full TypeScript support

To use TypeScript with full support for all TypeScript features, including tsconfig.json, you can use a third-party package. These instructions use tsx as an example but there are many other similar libraries available.

  1. Install the package as a development dependency using whatever package manager you're using for your project. For example, with npm:

    npm install --save-dev tsx
    
  2. Then you can run your TypeScript code via:

    npx tsx your-file.ts
    

    Or alternatively, you can run with node via:

    node --import=tsx your-file.ts
    

Type stripping

By default Node.js will execute TypeScript files that contains only erasable TypeScript syntax. Node.js will replace TypeScript syntax with whitespace, and no type checking is performed. To disable this feature, use the flag --no-strip-types.

Node.js ignores tsconfig.json files and therefore features that depend on settings within tsconfig.json, such as paths or converting newer JavaScript syntax to older standards, are intentionally unsupported. To get full TypeScript support, see Full TypeScript support.

The type stripping feature is designed to be lightweight. By intentionally not supporting syntaxes that require JavaScript code generation, and by replacing inline types with whitespace, Node.js can run TypeScript code without the need for source maps.

Type stripping is compatible with most versions of TypeScript but we recommend version 5.8 or newer with the following tsconfig.json settings:

{
  "compilerOptions": {
     "noEmit": true, // Optional - see note below
     "target": "esnext",
     "module": "nodenext",
     "rewriteRelativeImportExtensions": true,
     "erasableSyntaxOnly": true,
     "verbatimModuleSyntax": true
  }
}

Use the noEmit option if you intend to only execute *.ts files, for example a build script. You won't need this flag if you intend to distribute *.js files.

Determining module system

Node.js supports both CommonJS and ES Modules syntax in TypeScript files. Node.js will not convert from one module system to another; if you want your code to run as an ES module, you must use import and export syntax, and if you want your code to run as CommonJS you must use require and module.exports.

  • .ts files will have their module system determined the same way as .js files. To use import and export syntax, add "type": "module" to the nearest parent package.json.
  • .mts files will always be run as ES modules, similar to .mjs files.
  • .cts files will always be run as CommonJS modules, similar to .cjs files.
  • .tsx files are unsupported.

As in JavaScript files, file extensions are mandatory in import statements and import() expressions: import './file.ts', not import './file'. Because of backward compatibility, file extensions are also mandatory in require() calls: require('./file.ts'), not require('./file'), similar to how the .cjs extension is mandatory in require calls in CommonJS files.

The tsconfig.json option allowImportingTsExtensions will allow the TypeScript compiler tsc to type-check files with import specifiers that include the .ts extension.

TypeScript features

Since Node.js is only removing inline types, any TypeScript features that involve replacing TypeScript syntax with new JavaScript syntax will error.

The most prominent features that require transformation are:

  • Enum declarations
  • namespace with runtime code
  • parameter properties
  • import aliases

namespaces that do not contain runtime code are supported. This example will work correctly:

// This namespace is exporting a type
namespace TypeOnly {
   export type A = string;
}

This will result in ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX error:

// This namespace is exporting a value
namespace A {
   export let x = 1
}

Since Decorators are currently a TC39 Stage 3 proposal, they are not transformed and will result in a parser error. Node.js does not provide polyfills and thus will not support decorators until they are supported natively in JavaScript.

In addition, Node.js does not read tsconfig.json files and does not support features that depend on settings within tsconfig.json, such as paths or converting newer JavaScript syntax into older standards.

Importing types without type keyword

Due to the nature of type stripping, the type keyword is necessary to correctly strip type imports. Without the type keyword, Node.js will treat the import as a value import, which will result in a runtime error. The tsconfig option verbatimModuleSyntax can be used to match this behavior.

This example will work correctly:

import type { Type1, Type2 } from './module.ts';
import { fn, type FnParams } from './fn.ts';

This will result in a runtime error:

import { Type1, Type2 } from './module.ts';
import { fn, FnParams } from './fn.ts';

Non-file forms of input

Type stripping can be enabled for --eval and STDIN. The module system will be determined by --input-type, as it is for JavaScript.

TypeScript syntax is unsupported in the REPL, --check, and inspect.

Source maps

Since inline types are replaced by whitespace, source maps are unnecessary for correct line numbers in stack traces; and Node.js does not generate them.

Type stripping in dependencies

To discourage package authors from publishing packages written in TypeScript, Node.js refuses to handle TypeScript files inside folders under a node_modules path.

Paths aliases

tsconfig "paths" won't be transformed and therefore produce an error. The closest feature available is subpath imports with the limitation that they need to start with #.