You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/run-natively.md
+4-26Lines changed: 4 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,22 +4,18 @@ layout: learn
4
4
authors: AugustinMauroy
5
5
---
6
6
7
-
> **⚠️WARNING:** All content in this article uses Node.js experimental features. Please make sure you are using a version of Node.js that supports the features mentioned in this article. And remember that experimental features can change on future versions of Node.js.
7
+
> **⚠️WARNING⚠️:** All content in this article uses Node.js experimental features. Please make sure you are using a version of Node.js that supports the features mentioned in this article. And remember that experimental features can change on future versions of Node.js.
8
8
9
9
# Running TypeScript with a Node.js Itself
10
10
11
11
In the previous articles, we learned how to run TypeScript code using transpilation and with a runner. In this article, we will learn how to run TypeScript code using Node.js itself.
12
12
13
13
## Running TypeScript code with Node.js
14
14
15
-
Node.js has experimental support for some TypeScript syntax. You can write code that's valid TypeScript directly in Node.js without the need to transpile it first.
15
+
Since V22.6.0, Node.js has experimental support for some TypeScript syntax. You can write code that's valid TypeScript directly in Node.js without the need to transpile it first.
16
16
17
17
So how do you run typed JavaScript code with Node.js?
18
18
19
-
First, you need to install a nightly version of Node.js. You can download it from the [official Node.js website](https://nodejs.org/download/nightly/).
20
-
21
-
Then, you can run your file like this:
22
-
23
19
```bash
24
20
node --experimental-strip-types example.ts
25
21
```
@@ -33,28 +29,10 @@ In the future we all hope that this feature will be stable and available in the
33
29
34
30
At the time of writing, the experimental support for TypeScript in Node.js has some limitations. To allow typescript to run in node.js, our collaborators have chosen to only strip types from the code.
35
31
36
-
<!--
37
-
Maintainers note: this content is copy from docs (unreleased) and should be updated when the docs are released with a link to the official documentation
38
-
-->
39
-
40
-
Since Node.js is only removing inline types, any TypeScript features that
41
-
involve _replacing_ TypeScript syntax with new JavaScript syntax will error.
42
-
This is by design. To run TypeScript with such features, see
43
-
[Full TypeScript support][].
44
-
45
-
The most prominent unsupported features that require transformation are:
46
-
47
-
-`Enum`
48
-
-`experimentalDecorators`
49
-
-`namespaces`
50
-
- parameter properties
51
-
52
-
In addition, Node.js does not read `tsconfig.json` files and does not support
53
-
features that depend on settings within `tsconfig.json`, such as paths or
54
-
converting newer JavaScript syntax into older standards.
32
+
You can get more information on the [api docs](https://nodejs.org/docs/latest/api/typescript.html#unsupported-typescript-features)
55
33
56
34
## Important notes
57
35
58
36
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.
59
37
60
-
We can understand that this feature is experimental and has some limitations; if that doesn't suit your usecase, 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.
38
+
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