TypeScript ยท Chapter 2 of 44

TypeScript Setup & Install

To start using TypeScript, you need Node.js and npm installed on your machine. Once you have those, you can install the TypeScript compiler globally or as a project dependency using npm.

After installing, the `tsc` command becomes available, which compiles .ts files into .js files. Most real projects install TypeScript locally per project so that everyone on the team uses the same version.

Syntax
npm install -g typescript
tsc --version

Installing TypeScript

Run `npm install -g typescript` to install it globally, or `npm install --save-dev typescript` to add it to a single project. Global installs are handy for quick experiments.

Checking the version

After installation, run `tsc --version` to confirm TypeScript is installed correctly and see which version you have.

Example 1 (bash)
npm install -g typescript
Output
added 1 package

Installs the TypeScript compiler globally so `tsc` works from any folder.

Example 2 (bash)
tsc --version
Output
Version 5.4.5

Confirms that TypeScript was installed successfully.

Key points

  • TypeScript requires Node.js and npm to install.
  • `npm install -g typescript` installs it globally.
  • `npm install --save-dev typescript` installs it just for one project.
  • `tsc --version` checks the installed compiler version.
๐Ÿ’ก Note: Prefer a local, per-project install for real applications so the TypeScript version is locked and shared with your team.

๐Ÿ“ Quick Quiz

1. What must be installed before TypeScript?

2. Which command installs TypeScript globally?

3. How do you check your installed TypeScript version?