1
1
# Modules: TypeScript
2
2
3
+ <!-- YAML
4
+ changes:
5
+ - version: REPLACEME
6
+ pr-url: https://github.com/nodejs/node/pull/54283
7
+ description: Added `--experimental-transform-types` flag.
8
+ -->
9
+
10
+ > Stability: 1.0 - Early development
11
+
3
12
## Enabling
4
13
5
14
There are two ways to enable runtime TypeScript support in Node.js:
@@ -44,13 +53,15 @@ added: v22.6.0
44
53
> Stability: 1.0 - Early development
45
54
46
55
The flag [ ` --experimental-strip-types ` ] [ ] enables Node.js to run TypeScript
47
- files that contain only type annotations. Such files contain no TypeScript
48
- features that require transformation, such as enums or namespaces. Node.js will
49
- replace inline type annotations with whitespace, and no type checking is
50
- performed. TypeScript features that depend on settings within ` tsconfig.json ` ,
56
+ files. By default Node.js will execute only files that contain no
57
+ TypeScript features that require transformation, such as enums or namespaces.
58
+ Node.js will replace inline type annotations with whitespace,
59
+ and no type checking is performed.
60
+ To enable the transformation of such features
61
+ use the flag [ ` --experimental-transform-types ` ] [ ] .
62
+ TypeScript features that depend on settings within ` tsconfig.json ` ,
51
63
such as paths or converting newer JavaScript syntax to older standards, are
52
- intentionally unsupported. To get fuller TypeScript support, including support
53
- for enums and namespaces and paths, see [ Full TypeScript support] [ ] .
64
+ intentionally unsupported. To get full TypeScript support, see [ Full TypeScript support] [ ] .
54
65
55
66
The type stripping feature is designed to be lightweight.
56
67
By intentionally not supporting syntaxes that require JavaScript code
@@ -82,20 +93,24 @@ The `tsconfig.json` option `allowImportingTsExtensions` will allow the
82
93
TypeScript compiler ` tsc ` to type-check files with ` import ` specifiers that
83
94
include the ` .ts ` extension.
84
95
85
- ### Unsupported TypeScript features
96
+ ### TypeScript features
86
97
87
98
Since Node.js is only removing inline types, any TypeScript features that
88
- involve _ replacing_ TypeScript syntax with new JavaScript syntax will error.
89
- This is by design. To run TypeScript with such features, see
90
- [ Full TypeScript support] [ ] .
99
+ involve _ replacing_ TypeScript syntax with new JavaScript syntax will error,
100
+ unless the flag [ ` --experimental-transform-types ` ] [ ] is passed.
91
101
92
- The most prominent unsupported features that require transformation are:
102
+ The most prominent features that require transformation are:
93
103
94
104
* ` Enum `
95
- * ` experimentalDecorators `
96
105
* ` namespaces `
106
+ * ` legacy module `
97
107
* parameter properties
98
108
109
+ Since Decorators are currently a [ TC39 Stage 3 proposal] ( https://github.com/tc39/proposal-decorators )
110
+ and will soon be supported by the JavaScript engine,
111
+ they are not transformed and will result in a parser error.
112
+ This is a temporary limitation and will be resolved in the future.
113
+
99
114
In addition, Node.js does not read ` tsconfig.json ` files and does not support
100
115
features that depend on settings within ` tsconfig.json ` , such as paths or
101
116
converting newer JavaScript syntax into older standards.
@@ -132,8 +147,9 @@ TypeScript syntax is unsupported in the REPL, STDIN input, `--print`, `--check`,
132
147
### Source maps
133
148
134
149
Since inline types are replaced by whitespace, source maps are unnecessary for
135
- correct line numbers in stack traces; and Node.js does not generate them. For
136
- source maps support, see [ Full TypeScript support] [ ] .
150
+ correct line numbers in stack traces; and Node.js does not generate them.
151
+ When [ ` --experimental-transform-types ` ] [ ] is enabled, source-maps
152
+ are enabled by default.
137
153
138
154
### Type stripping in dependencies
139
155
@@ -145,6 +161,7 @@ a `node_modules` path.
145
161
[ ES Modules ] : esm.md
146
162
[ Full TypeScript support ] : #full-typescript-support
147
163
[ `--experimental-strip-types` ] : cli.md#--experimental-strip-types
164
+ [ `--experimental-transform-types` ] : cli.md#--experimental-transform-types
148
165
[ `tsx` ] : https://tsx.is/
149
166
[ `verbatimModuleSyntax` ] : https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax
150
167
[ file extensions are mandatory ] : esm.md#mandatory-file-extensions
0 commit comments