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/introduction.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -32,17 +32,17 @@ function isAdult(user: User): boolean {
32
32
returnuser.age>=18;
33
33
}
34
34
35
-
const justine:User= {
35
+
const justine = {
36
36
name: 'Justine',
37
37
age: 23,
38
-
};
38
+
}satisfiesUser;
39
39
40
-
const isJustineAnAdult:boolean=isAdult(justine);
40
+
const isJustineAnAdult =isAdult(justine);
41
41
```
42
42
43
43
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 deduce types for us. For example, variable `isJustineAnAdult`would be of type `boolean` even if we didn't type it explicitly or `justine` would be valid argument for our function even if 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 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.
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/run-natively.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -12,21 +12,21 @@ In the previous articles, we learned how to run TypeScript code using transpilat
12
12
13
13
## Running TypeScript code with Node.js
14
14
15
-
Node.js has experimental support for TypeScript. You can run TypeScript code directly in Node.js without the need to compile it first.
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.
16
16
17
-
So how do you run TypeScript code with Node.js?
17
+
So how do you run typed JavaScript code with Node.js?
18
18
19
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
20
21
-
Then, you can run your TypeScript code like this:
21
+
Then, you can run your file like this:
22
22
23
23
```bash
24
24
node --experimental-strip-types example.ts
25
25
```
26
26
27
27
The `--experimental-strip-types` flag tells Node.js to strip the type annotations from the TypeScript code before running it.
28
28
29
-
And that's it! You can now run TypeScript code directly in Node.js without the need to compile it first.
29
+
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.
30
30
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.
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
59
60
-
We can understand that this feature is experimental and has some limitations, and this may disappoint you. So please be patient and wait for the stable version of this feature. And **NEVER** spam us. If you are happy, you can share these articles on social media and tell your friends about this feature.
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.
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/typescript/transpile.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -36,11 +36,11 @@ const justine: User = {
36
36
const isJustineAnAdult:boolean=isAdult(justine);
37
37
```
38
38
39
-
**Step 2:** Install TypeScript globally using npm:
39
+
**Step 2:** Install TypeScript globally using a package manager:
40
40
41
-
If you want to discover npm, you can check our [our introduction to the npm package manager](/learn/getting-started/an-introduction-to-the-npm-package-manager)
41
+
In this example we're going to use npm, you can check our [our introduction to the npm package manager](/learn/getting-started/an-introduction-to-the-npm-package-manager) for more information.
42
42
43
-
There are two ways to install TypeScript, globally or locally. We recommend installing it globally for the sake of simplicity.
43
+
There are two ways to install TypeScript, globally or locally. We do not recommend installing it globally for the sake of everyone working with you.
44
44
45
45
```bash displayName="Install TypeScript globally"
46
46
npm i -g typescript # -g is a shorthand for --global
0 commit comments