{
  "type": "module",
  "source": "doc/api/typescript.md",
  "modules": [
    {
      "textRaw": "Modules: TypeScript",
      "name": "modules:_typescript",
      "meta": {
        "changes": [
          {
            "version": "v23.6.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": 1,
      "stabilityText": ".1 - Active development",
      "modules": [
        {
          "textRaw": "Enabling",
          "name": "enabling",
          "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>",
          "type": "module",
          "displayName": "Enabling"
        },
        {
          "textRaw": "Full TypeScript support",
          "name": "full_typescript_support",
          "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.is/\"><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>",
          "type": "module",
          "displayName": "Full TypeScript support"
        },
        {
          "textRaw": "Type stripping",
          "name": "type_stripping",
          "meta": {
            "added": [
              "v22.6.0"
            ],
            "changes": []
          },
          "stability": 1,
          "stabilityText": ".1 - Active development",
          "desc": "<p>The flag <a href=\"cli.html#--no-experimental-strip-types\"><code>--no-experimental-strip-types</code></a> prevents Node.js from running TypeScript\nfiles. By default Node.js will execute only files that contain no\nTypeScript features that require transformation, such as enums or namespaces.\nNode.js will replace inline type annotations with whitespace,\nand no type checking is performed.\nTo enable the transformation of such features\nuse the flag <a href=\"cli.html#--experimental-transform-types\"><code>--experimental-transform-types</code></a>.\nTypeScript features 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 works with most versions of TypeScript\nbut we recommend version 5.7 or newer with the following <code>tsconfig.json</code> settings:</p>\n<pre><code class=\"language-json\">{\n  \"compilerOptions\": {\n     \"target\": \"esnext\",\n     \"module\": \"nodenext\",\n     \"allowImportingTsExtensions\": true,\n     \"rewriteRelativeImportExtensions\": true,\n     \"verbatimModuleSyntax\": true\n  }\n}\n</code></pre>",
          "modules": [
            {
              "textRaw": "Determining module system",
              "name": "determining_module_system",
              "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>",
              "type": "module",
              "displayName": "Determining module system"
            },
            {
              "textRaw": "TypeScript features",
              "name": "typescript_features",
              "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,\nunless the flag <a href=\"cli.html#--experimental-transform-types\"><code>--experimental-transform-types</code></a> is passed.</p>\n<p>The most prominent features that require transformation are:</p>\n<ul>\n<li><code>Enum</code></li>\n<li><code>namespaces</code></li>\n<li><code>legacy module</code></li>\n<li>parameter properties</li>\n</ul>\n<p>Since Decorators are currently a <a href=\"https://github.com/tc39/proposal-decorators\">TC39 Stage 3 proposal</a>\nand will soon be supported by the JavaScript engine,\nthey are not transformed and will result in a parser error.\nThis is a temporary limitation and will be resolved in the future.</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>",
              "type": "module",
              "displayName": "TypeScript features"
            },
            {
              "textRaw": "Importing types without `type` keyword",
              "name": "importing_types_without_`type`_keyword",
              "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>",
              "type": "module",
              "displayName": "Importing types without `type` keyword"
            },
            {
              "textRaw": "Non-file forms of input",
              "name": "non-file_forms_of_input",
              "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>",
              "type": "module",
              "displayName": "Non-file forms of input"
            },
            {
              "textRaw": "Source maps",
              "name": "source_maps",
              "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.\nWhen <a href=\"cli.html#--experimental-transform-types\"><code>--experimental-transform-types</code></a> is enabled, source-maps\nare enabled by default.</p>",
              "type": "module",
              "displayName": "Source maps"
            },
            {
              "textRaw": "Type stripping in dependencies",
              "name": "type_stripping_in_dependencies",
              "desc": "<p>To discourage package authors from publishing packages written in TypeScript,\nNode.js will by default refuse to handle TypeScript files inside folders under\na <code>node_modules</code> path.</p>",
              "type": "module",
              "displayName": "Type stripping in dependencies"
            },
            {
              "textRaw": "Paths aliases",
              "name": "paths_aliases",
              "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>",
              "type": "module",
              "displayName": "Paths aliases"
            }
          ],
          "type": "module",
          "displayName": "Type stripping"
        }
      ],
      "type": "module",
      "displayName": "Modules: TypeScript"
    }
  ]
}