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
**[TypeScript](https://www.typescriptlang.org)** is an open-source language maintained and developed by Microsoft. It's loved and used by a lot of software developers around the world.
11
+
**[TypeScript](https://www.typescriptlang.org)** is an open-source language maintained and developed by Microsoft.
12
12
13
-
Basically, TypeScript add adds additional syntax to JavaScript to support a tighter integration with your editor. Catch errors early in your editor or in your CI/CD pipeline, and write more maintainable code.
13
+
Basically, TypeScript adds additional syntax to JavaScript to support a tighter integration with your editor. Catch errors early in your editor or in your CI/CD pipeline, and write more maintainable code.
14
14
15
15
We can talk about other TypeScript benefits later, let's see some examples now!
The first part (with the `type` keyword) is responsible for declaring our custom object type representing users. Later we utilize this newly created type to create function `isAdult` that accepts one argument of type `User` and returns `boolean`. After this, we create `justine`, our example data that can be used for calling the previously defined function. Finally, we create a new variable with information on whether `justine` is an adult.
44
44
45
-
There are additional things about this example that you should know. Firstly, if we would not comply with declared types, TypeScript would alarm us that something is wrong and prevent misuse. Secondly, not everything must be typed explicitly - TypeScript is very smart and can infer types for us. For example, variable `isJustineAnAdult` is of type `boolean` even if we didn't type it explicitly or`justine` would be valid argument for our function even though we didn't declare this variable as of `User` type.
45
+
There are additional things about this example that you should know. Firstly, if we do not comply with the declared types, TypeScript will inform us that something is wrong and prevent misuse. Secondly, not everything must be typed explicitly—TypeScript infers types for us. For example, the variable `isJustineAnAdult` is of type `boolean` even if we didn't type it explicitly, and`justine` would be a valid argument for our function even though we didn't declare this variable as of `User` type.
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/run-natively.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ 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 in future versions of Node.js.
8
8
9
9
# Running TypeScript Natively
10
10
@@ -14,22 +14,22 @@ In the previous articles, we learned how to run TypeScript code using transpilat
14
14
15
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
-
So how do you run typed JavaScript code with Node.js?
17
+
So how do you run TypeScript code with Node.js?
18
18
19
19
```bash
20
20
node --experimental-strip-types example.ts
21
21
```
22
22
23
23
The `--experimental-strip-types` flag tells Node.js to strip the type annotations from the TypeScript code before running it.
24
24
25
-
And that's it! You can now run typed JavaScript code directly in Node.js without the need to transpile it first, and use TypeScript to catch type-related errors.
26
-
In the future we all hope that this feature will be stable and available in the LTS version of Node.js, so that we can all enjoy it without any additional steps.
25
+
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.
26
+
Future versions of Node.js will include support for TypeScript without the need for a command line flag.
27
27
28
28
## Limitations
29
29
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.
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.
31
31
32
-
You can get more information on the [api docs](https://nodejs.org/docs/latest/api/typescript.html#unsupported-typescript-features)
32
+
You can get more information on the [API docs](https://nodejs.org/docs/latest/api/typescript.html#unsupported-typescript-features)
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/run.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ In the previous article, we learned how to run TypeScript code using transpilati
10
10
11
11
## Running TypeScript code with `ts-node`
12
12
13
-
[ts-node](https://typestrong.org/ts-node/) is a TypeScript execution environment for node.js. It allows you to run TypeScript code directly in node.js without the need to compile it first. But it's not typechecking your code. So we recommend to type check your code first with `tsc` and then run it with `ts-node` before shipping it.
13
+
[ts-node](https://typestrong.org/ts-node/) is a TypeScript execution environment for Node.js. It allows you to run TypeScript code directly in Node.js without the need to compile it first. Note, however, that it does not type check your code. So we recommend to type check your code first with `tsc` and then run it with `ts-node` before shipping it.
14
14
15
15
To use `ts-node`, you need to install it first:
16
16
@@ -26,7 +26,7 @@ npx ts-node example.ts
26
26
27
27
## Running TypeScript code with `tsx`
28
28
29
-
[tsx](https://tsx.is/) is another TypeScript execution environment for node.js. It allows you to run TypeScript code directly in node.js without the need to compile it first. But it's not typechecking your code. So we recommend to type check your code first with `tsc` and then run it with `tsx` before shipping it.
29
+
[tsx](https://tsx.is/) is another TypeScript execution environment for Node.js. It allows you to run TypeScript code directly in Node.js without the need to compile it first. Note, however, that it does not type check your code. So we recommend to type check your code first with `tsc` and then run it with `tsx` before shipping it.
0 commit comments