• Installing TypeScript
  • Write Your First TypeScript Program

Introduction to TypeScript

TypeScript is an improved version of JavaScript. It includes everything that JavaScript has, plus extra features like data types, interfaces, and enums.

These features help developers find mistakes while writing code instead of after running it.

TypeScript makes code easier to read, understand, and maintain, especially in large projects.

Before running, TypeScript code is converted into JavaScript because browsers and Node.js can only run JavaScript.


Installing TypeScript

Before TypeScript, you need to install Node.js on your system.

Step 1: Install Node.js

  1. Visit the official Node.js website:
  2. Download the LTS (Long-Term Support) version.
  3. Run the installer and complete the installation.
Verify the Installation

Open Command Prompt or Terminal and run:

node -v

Check the npm version:

npm -v

Step 2: Install TypeScript

Install TypeScript globally using npm:

npm install -g typescript

What does this command mean?

  • npm → Node Package Manager
  • install → Installs a package
  • -g → Installs the package globally, so it can be used from any folder
  • typescript → The TypeScript package

Step 3: Verify TypeScript Installation

tsc -v

Write Your First TypeScript Program

Create a file named: hello.ts

let message: string = "Hello, TypeScript!";
console.log(message);

Compile the TypeScript File

tsc hello.ts

Run the JavaScript File

node hello.js

Output: Hello, TypeScript!