Skip to content

Commit 02c7f64

Browse files
chore: update running typescript natively documentation
1 parent cf7233e commit 02c7f64

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

apps/site/pages/en/learn/typescript/run-natively.md

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,39 @@ authors: AugustinMauroy, khaosdoctor, jakebailey, robpalme
66

77
# Running TypeScript Natively
88

9-
Since v22.18.0, Node.js enables "type stripping" by default. If you are using v22.18.0 or later and your source code contains only [erasable typescript syntax](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8-beta/#the---erasablesyntaxonly-option), you do not need this article.
9+
You can write code that's valid TypeScript directly in Node.js without the need to transpile it first.
1010

11-
## Running TypeScript code with Node.js
11+
If you are using v22.18.0 or later and your source code contains only [erasable TypeScript syntax](https://devblogs.microsoft.com/typescript/announcing-typescript-5-8-beta/#the---erasablesyntaxonly-option), can you just run directly without any flag.
1212

13-
Since V22.6.0, Node.js has experimental support for some TypeScript syntax via "type stripping". You can write code that's valid TypeScript directly in Node.js without the need to transpile it first.
13+
```bash
14+
node example.ts
15+
```
1416

15-
The [`--experimental-strip-types`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--experimental-strip-types) flag tells Node.js to strip the type annotations from the TypeScript code before running it.
17+
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.
1618

1719
```bash
1820
node --experimental-strip-types example.ts
1921
```
2022

2123
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.
2224

23-
In V22.7.0 this experimental support was extended to transform TypeScript-only syntax, like `enum`s and `namespace`, with the addition of the [`--experimental-transform-types`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--experimental-transform-types) flag. 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:
25+
You can disable it via [`--no-experimental-strip-types`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--no-experimental-strip-types) flag if needed.
2426

2527
```bash
26-
node --experimental-transform-types another-example.ts
28+
node --no-experimental-strip-types example.ts
2729
```
2830

29-
From v22.18.0 onwards, type stripping is enabled by default (you can disable it via [`--no-experimental-strip-types`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--no-experimental-strip-types)), enabling you to run any supported syntax, so running files like the one below with `node file.ts` is supported:
31+
In v22.7.0 the flag [`--experimental-transform-types`](https://nodejs.org/docs/latest-v22.x/api/cli.html#--experimental-transform-types) was added to enable TypeScript-only syntax that requires transformation, like `enum`s 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:
3032

31-
```ts
32-
function foo(bar: number): string {
33-
return 'hello';
34-
}
33+
```bash
34+
node --experimental-transform-types another-example.ts
3535
```
3636

37-
However, running any code that requires transformations, like the code below still needs the use of `--experimental-transform-types`:
37+
This flag is opt-in, and you should only use it if your code requires it.
3838

39-
```ts
40-
enum MyEnum {
41-
A,
42-
B,
43-
}
39+
## Constraints
4440

45-
console.log(MyEnum.A);
46-
```
47-
48-
## Limitations
49-
50-
At the time of writing, the experimental support for TypeScript in Node.js has some limitations.
41+
The support for TypeScript in Node.js has some constraints to keep in mind:
5142

5243
You can get more information on the [API docs](https://nodejs.org/docs/latest-v22.x/api/typescript.html#typescript-features).
5344

@@ -56,9 +47,3 @@ You can get more information on the [API docs](https://nodejs.org/docs/latest-v2
5647
The Node.js TypeScript loader ([Amaro](https://github.com/nodejs/amaro)) does not need or use `tsconfig.json` to run TypeScript code.
5748

5849
We recommend configuring your editor and `tsc` to reflect Node.js behavior by creating a `tsconfig.json` using the `compilerOptions` listed [here](https://nodejs.org/api/typescript.html#type-stripping), as well as using TypeScript version **5.7 or higher**.
59-
60-
## Important notes
61-
62-
Thanks to all the contributors who have made this feature possible. We hope that this feature will be stable and available in the LTS version of Node.js soon.
63-
64-
We can understand that this feature is experimental and has some limitations; if that 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.

0 commit comments

Comments
 (0)