Skip to content

Commit

Permalink
content(learn): update from feedback
Browse files Browse the repository at this point in the history
Co-Authored-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
AugustinMauroy and aduh95 committed Jul 30, 2024
1 parent dfe4e40 commit 215a5c7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apps/site/pages/en/learn/typescript/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ function isAdult(user: User): boolean {
return user.age >= 18;
}

const justine: User = {
const justine = {
name: 'Justine',
age: 23,
};
} satisfies User;

const isJustineAnAdult: boolean = isAdult(justine);
const isJustineAnAdult = isAdult(justine);
```

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.

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

## How to run TypeScript code

Expand Down
10 changes: 5 additions & 5 deletions apps/site/pages/en/learn/typescript/run-natively.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ In the previous articles, we learned how to run TypeScript code using transpilat

## Running TypeScript code with Node.js

Node.js has experimental support for TypeScript. You can run TypeScript code directly in Node.js without the need to compile it first.
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 TypeScript code with Node.js?
So how do you run typed JavaScript code with Node.js?

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 TypeScript code like this:
Then, you can run your file like this:

```bash
node --experimental-strip-types example.ts
```

The `--experimental-strip-types` flag tells Node.js to strip the type annotations from the TypeScript code before running it.

And that's it! You can now run TypeScript code directly in Node.js without the need to compile it first.
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.
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.

## Limitations
Expand Down Expand Up @@ -57,4 +57,4 @@ converting newer JavaScript syntax into older standards.

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.

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.
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.
6 changes: 3 additions & 3 deletions apps/site/pages/en/learn/typescript/transpile.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const justine: User = {
const isJustineAnAdult: boolean = isAdult(justine);
```

**Step 2:** Install TypeScript globally using npm:
**Step 2:** Install TypeScript globally using a package manager:

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

There are two ways to install TypeScript, globally or locally. We recommend installing it globally for the sake of simplicity.
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.

```bash displayName="Install TypeScript globally"
npm i -g typescript # -g is a shorthand for --global
Expand Down

0 comments on commit 215a5c7

Please sign in to comment.