TypeScript Installation

TypeScript tutorial

TypeScript Installation

Prerequisites

Before TypeScript Installation, make sure you have Node.js installed on your system.

  • Node.js includes npm (Node Package Manager)
  • TypeScript is installed using npm

Step 1: Check Node.js Installation

Open Command Prompt / Terminal and run:

node -v
npm -v

If versions appear, Node.js is installed.
If not, download and install Node.js from the official site.


Step 2: Install TypeScript (Global Installation)

Run the following command:

npm install -g typescript

This installs the TypeScript Compiler (tsc) globally.


Step 3: Verify Installation

Check the installed version:

tsc -v

Example output:

Version 5.x.x

Step 4: Create Your First TypeScript File

Create a file named:

app.ts

Add this code:


Step 5: Compile TypeScript to JavaScript

Run:

tsc app.ts

This will generate:

app.js

Step 6: Run the JavaScript File

node app.js

Output:

Hello TypeScript

Alternative: Local Installation (Recommended for Projects)

Instead of global installations, you can install TypeScript inside a project.

npm init -y
npm install --save-dev typescript

Run TypeScript using:

npx tsc -v

Create tsconfig.json (Optional but Recommended)

tsc --init

This file controls:

  • Target JavaScript version

  • Strict type checking

  • Module system

  • Output directory


Common Installation Errors & Fixes

tsc is not recognized

  •  Restart terminal
  • Check npm global path
  • Reinstall Node.js

 Permission Error (Linux/Mac)

sudo npm install -g typescript

Installation Summary

TaskCommand
Install TypeScriptnpm install -g typescript
Check Versiontsc -v
Compile Filetsc file.ts
Initialize Configtsc --init

You may also like...