{
  "type": "module",
  "source": "doc/api/typescript.md",
  "modules": [
    {
      "textRaw": "Modules: TypeScript",
      "name": "modules:_typescript",
      "introduced_in": "v22.6.0",
      "type": "module",
      "meta": {
        "changes": [
          {
            "version": "v26.0.0",
            "pr-url": "https://github.com/nodejs/node/pull/61803",
            "description": "Removed `--experimental-transform-types` flag."
          },
          {
            "version": [
              "v25.2.0",
              "v24.12.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/60600",
            "description": "Type stripping is now stable."
          },
          {
            "version": [
              "v24.3.0",
              "v22.18.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/58643",
            "description": "Type stripping no longer emits an experimental warning."
          },
          {
            "version": [
              "v23.6.0",
              "v22.18.0"
            ],
            "pr-url": "https://github.com/nodejs/node/pull/56350",
            "description": "Type stripping is enabled by default."
          },
          {
            "version": "v22.7.0",
            "pr-url": "https://github.com/nodejs/node/pull/54283",
            "description": "Added `--experimental-transform-types` flag."
          }
        ]
      },
      "stability": 2,
      "stabilityText": "Stable",
      "modules": [
        {
          "textRaw": "Enabling",
          "name": "enabling",
          "type": "module",
          "desc": "<p>There are two ways to enable runtime TypeScript support in Node.js:</p>\n<ol>\n<li>\n<p>For <a href=\"#full-typescript-support\">full support</a> of all of TypeScript's syntax and features, including\nusing any version of TypeScript, use a third-party package.</p>\n</li>\n<li>\n<p>For lightweight support, you can use the built-in support for\n<a href=\"#type-stripping\">type stripping</a>.</p>\n</li>\n</ol>",
          "displayName": "Enabling"
        },
        {
          "textRaw": "Full TypeScript support",
          "name": "full_typescript_support",
          "type": "module",
          "desc": "<p>To use TypeScript with full support for all TypeScript features, including\n<code>tsconfig.json</code>, you can use a third-party package. These instructions use\n<a href=\"https://tsx.hirok.io/\"><code>tsx</code></a> as an example but there are many other similar libraries available.</p>\n<ol>\n<li>\n<p>Install the package as a development dependency using whatever package\nmanager you're using for your project. For example, with <code>npm</code>:</p>\n<pre><code class=\"language-bash\">npm install --save-dev tsx\n</code></pre>\n</li>\n<li>\n<p>Then you can run your TypeScript code via:</p>\n<pre><code class=\"language-bash\">npx tsx your-file.ts\n</code></pre>\n<p>Or alternatively, you can run with <code>node</code> via:</p>\n<pre><code class=\"language-bash\">node --import=tsx your-file.ts\n</code></pre>\n</li>\n</ol>",
          "displayName": "Full TypeScript support"
        },
        {
          "textRaw": "Type stripping",
          "name": "type_stripping",
          "type": "module",
          "meta": {
            "added": [
              "v22.6.0"
            ],
            "changes": [
              {
                "version": [
                  "v25.2.0",
                  "v24.12.0"
                ],
                "pr-url": "https://github.com/nodejs/node/pull/60600",
                "description": "Type stripping is now stable."
              }
            ]
          },
          "desc": "<p>By default Node.js will execute TypeScript files that contains only\nerasable TypeScript syntax.\nNode.js will replace TypeScript syntax with whitespace,\nand no type checking is performed.\nTo disable this feature, use the flag <a href=\"cli.html#--no-strip-types\"><code>--no-strip-types</code></a>.</p>\n<p>Node.js ignores <code>tsconfig.json</code> files and therefore\nfeatures that depend on settings within <code>tsconfig.json</code>,\nsuch as paths or converting newer JavaScript syntax to older standards, are\nintentionally unsupported. To get full TypeScript support, see <a href=\"#full-typescript-support\">Full TypeScript support</a>.</p>\n<p>The type stripping feature is designed to be lightweight.\nBy intentionally not supporting syntaxes that require JavaScript code\ngeneration, and by replacing inline types with whitespace, Node.js can run\nTypeScript code without the need for source maps.</p>\n<p>Type stripping is compatible with most versions of TypeScript\nbut we recommend version 5.8 or newer with the following <code>tsconfig.json</code> settings:</p>\n<pre><code class=\"language-json\">{\n  \"compilerOptions\": {\n     \"noEmit\": true, // Optional - see note below\n     \"target\": \"esnext\",\n     \"module\": \"nodenext\",\n     \"rewriteRelativeImportExtensions\": true,\n     \"erasableSyntaxOnly\": true,\n     \"verbatimModuleSyntax\": true\n  }\n}\n</code></pre>\n<p>Use the <code>noEmit</code> option if you intend to only execute <code>*.ts</code> files, for example\na build script. You won't need this flag if you intend to distribute <code>*.js</code>\nfiles.</p>",
          "modules": [
            {
              "textRaw": "Determining module system",
              "name": "determining_module_system",
              "type": "module",
              "desc": "<p>Node.js supports both <a href=\"modules.html\">CommonJS</a> and <a href=\"esm.html\">ES Modules</a> syntax in TypeScript\nfiles. Node.js will not convert from one module system to another; if you want\nyour code to run as an ES module, you must use <code>import</code> and <code>export</code> syntax, and\nif you want your code to run as CommonJS you must use <code>require</code> and\n<code>module.exports</code>.</p>\n<ul>\n<li><code>.ts</code> files will have their module system determined <a href=\"packages.html#determining-module-system\">the same way as <code>.js</code>\nfiles.</a> To use <code>import</code> and <code>export</code> syntax, add <code>\"type\": \"module\"</code> to the\nnearest parent <code>package.json</code>.</li>\n<li><code>.mts</code> files will always be run as ES modules, similar to <code>.mjs</code> files.</li>\n<li><code>.cts</code> files will always be run as CommonJS modules, similar to <code>.cjs</code> files.</li>\n<li><code>.tsx</code> files are unsupported.</li>\n</ul>\n<p>As in JavaScript files, <a href=\"esm.html#mandatory-file-extensions\">file extensions are mandatory</a> in <code>import</code> statements\nand <code>import()</code> expressions: <code>import './file.ts'</code>, not <code>import './file'</code>. Because\nof backward compatibility, file extensions are also mandatory in <code>require()</code>\ncalls: <code>require('./file.ts')</code>, not <code>require('./file')</code>, similar to how the\n<code>.cjs</code> extension is mandatory in <code>require</code> calls in CommonJS files.</p>\n<p>The <code>tsconfig.json</code> option <code>allowImportingTsExtensions</code> will allow the\nTypeScript compiler <code>tsc</code> to type-check files with <code>import</code> specifiers that\ninclude the <code>.ts</code> extension.</p>",
              "displayName": "Determining module system"
            },
            {
              "textRaw": "TypeScript features",
              "name": "typescript_features",
              "type": "module",
              "desc": "<p>Since Node.js is only removing inline types, any TypeScript features that\ninvolve <em>replacing</em> TypeScript syntax with new JavaScript syntax will error.</p>\n<p>The most prominent features that require transformation are:</p>\n<ul>\n<li><code>Enum</code> declarations</li>\n<li><code>namespace</code> with runtime code</li>\n<li>parameter properties</li>\n<li>import aliases</li>\n</ul>\n<p><code>namespace</code>s that do not contain runtime code are supported.\nThis example will work correctly:</p>\n<pre><code class=\"language-ts\">// This namespace is exporting a type\nnamespace TypeOnly {\n   export type A = string;\n}\n</code></pre>\n<p>This will result in <a href=\"errors.html#err_unsupported_typescript_syntax\"><code>ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX</code></a> error:</p>\n<pre><code class=\"language-ts\">// This namespace is exporting a value\nnamespace A {\n   export let x = 1\n}\n</code></pre>\n<p>Since Decorators are currently a <a href=\"https://github.com/tc39/proposal-decorators\">TC39 Stage 3 proposal</a>,\nthey are not transformed and will result in a parser error.\nNode.js does not provide polyfills and thus will not support decorators until\nthey are supported natively in JavaScript.</p>\n<p>In addition, Node.js does not read <code>tsconfig.json</code> files and does not support\nfeatures that depend on settings within <code>tsconfig.json</code>, such as paths or\nconverting newer JavaScript syntax into older standards.</p>",
              "displayName": "TypeScript features"
            },
            {
              "textRaw": "Importing types without `type` keyword",
              "name": "importing_types_without_`type`_keyword",
              "type": "module",
              "desc": "<p>Due to the nature of type stripping, the <code>type</code> keyword is necessary to\ncorrectly strip type imports. Without the <code>type</code> keyword, Node.js will treat the\nimport as a value import, which will result in a runtime error. The tsconfig\noption <a href=\"https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax\"><code>verbatimModuleSyntax</code></a> can be used to match this behavior.</p>\n<p>This example will work correctly:</p>\n<pre><code class=\"language-ts\">import type { Type1, Type2 } from './module.ts';\nimport { fn, type FnParams } from './fn.ts';\n</code></pre>\n<p>This will result in a runtime error:</p>\n<pre><code class=\"language-ts\">import { Type1, Type2 } from './module.ts';\nimport { fn, FnParams } from './fn.ts';\n</code></pre>",
              "displayName": "Importing types without `type` keyword"
            },
            {
              "textRaw": "Non-file forms of input",
              "name": "non-file_forms_of_input",
              "type": "module",
              "desc": "<p>Type stripping can be enabled for <code>--eval</code> and STDIN. The module system\nwill be determined by <code>--input-type</code>, as it is for JavaScript.</p>\n<p>TypeScript syntax is unsupported in the REPL, <code>--check</code>, and\n<code>inspect</code>.</p>",
              "displayName": "Non-file forms of input"
            },
            {
              "textRaw": "Source maps",
              "name": "source_maps",
              "type": "module",
              "desc": "<p>Since inline types are replaced by whitespace, source maps are unnecessary for\ncorrect line numbers in stack traces; and Node.js does not generate them.</p>",
              "displayName": "Source maps"
            },
            {
              "textRaw": "Type stripping in dependencies",
              "name": "type_stripping_in_dependencies",
              "type": "module",
              "desc": "<p>To discourage package authors from publishing packages written in TypeScript,\nNode.js refuses to handle TypeScript files inside folders under a <code>node_modules</code>\npath.</p>",
              "displayName": "Type stripping in dependencies"
            },
            {
              "textRaw": "Paths aliases",
              "name": "paths_aliases",
              "type": "module",
              "desc": "<p><a href=\"https://www.typescriptlang.org/tsconfig/#paths\"><code>tsconfig</code> \"paths\"</a> won't be transformed and therefore produce an error. The closest\nfeature available is <a href=\"packages.html#subpath-imports\">subpath imports</a> with the limitation that they need to start\nwith <code>#</code>.</p>",
              "displayName": "Paths aliases"
            }
          ],
          "displayName": "Type stripping"
        }
      ],
      "displayName": "Modules: TypeScript"
    }
  ]
}