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
content(learn): remove global install of tsc
  • Loading branch information
AugustinMauroy committed Jul 30, 2024
commit 96bd205cc188c6906c366446cdc69d8168b7ff99
24 changes: 12 additions & 12 deletions apps/site/pages/en/learn/typescript/transpile.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
````md
---
title: Running TypeScript code using transpilation
layout: learn
Expand Down Expand Up @@ -28,35 +29,30 @@ 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);
```
````

**Step 2:** Install TypeScript globally using a package manager:
**Step 2:** Install TypeScript locally using a 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 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
```

```bash displayName="Install TypeScript locally"
npm i -D typescript # -D is a shorthand for --save-dev
```

**Step 3:** Compile your TypeScript code to JavaScript using the `tsc` command:

```bash
tsc example.ts
npx tsc example.ts
```

> **NOTE:** You can also use `npx tsc example.ts` if you don't want to install TypeScript globally. [npx](https://www.npmjs.com/package/npx) is a tool that allows you to run Node.js packages without installing them globally.
> **NOTE:** `npx` is a tool that allows you to run Node.js packages without installing them globally.

`tsc` is the TypeScript compiler which will take our TypeScript code and compile it to JavaScript.
This command will result in a new file named `example.js` that we can run using Node.js.
Expand Down Expand Up @@ -122,3 +118,7 @@ Found 3 errors in the same file, starting at: example.ts:12
```

As you can see, TypeScript is very helpful in catching bugs before they even happen. This is one of the reasons why TypeScript is so popular among developers.

```

```