Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

content(learn): update resources about typescript #6951

Merged
merged 10 commits into from
Sep 16, 2024
Prev Previous commit
Next Next commit
update
  • Loading branch information
AugustinMauroy committed Aug 9, 2024
commit b6bcd4038280ae11bf30033fb9e9b94a74f1520d
30 changes: 4 additions & 26 deletions apps/site/pages/en/learn/typescript/run-natively.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,18 @@ layout: learn
authors: AugustinMauroy
---

> **⚠️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.
> **⚠️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.
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

# Running TypeScript with a Node.js Itself
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

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.

## Running TypeScript code with Node.js

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

So how do you run typed JavaScript code with Node.js?
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

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/).

Then, you can run your file like this:

```bash
node --experimental-strip-types example.ts
```
Expand All @@ -33,28 +29,10 @@ In the future we all hope that this feature will be stable and available in the

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.
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

<!--
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
-->

Since Node.js is only removing inline types, any TypeScript features that
involve _replacing_ TypeScript syntax with new JavaScript syntax will error.
This is by design. To run TypeScript with such features, see
[Full TypeScript support][].

The most prominent unsupported features that require transformation are:

- `Enum`
- `experimentalDecorators`
- `namespaces`
- parameter properties

In addition, Node.js does not read `tsconfig.json` files and does not support
features that depend on settings within `tsconfig.json`, such as paths or
converting newer JavaScript syntax into older standards.
You can get more information on the [api docs](https://nodejs.org/docs/latest/api/typescript.html#unsupported-typescript-features)
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

## Important notes

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.
AugustinMauroy marked this conversation as resolved.
Show resolved Hide resolved

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.
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.
4 changes: 2 additions & 2 deletions apps/site/site.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"websiteBadges": {
"index": {
"startDate": "2024-07-01T00:00:00.000Z",
"endDate": "2024-08-01T00:00:00.000Z",
"startDate": "2024-08-01T00:00:00.000Z",
"endDate": "2024-09-01T00:00:00.000Z",
"kind": "default",
"title": "Discover",
"text": "TypeScript in Node.js",
Expand Down
Loading