TypeScript Installation
🛠️ TypeScript Installation
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:
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:
This installs the TypeScript Compiler (tsc) globally.
Step 3: Verify Installation
Check the installed version:
Example output:
Step 4: Create Your First TypeScript File
Create a file named:
Add this code:
Step 5: Compile TypeScript to JavaScript
Run:
This will generate:
Step 6: Run the JavaScript File
Output:
Alternative: Local Installation (Recommended for Projects)
Instead of global installation, you can install TypeScript inside a project.
Run TypeScript using:
Create tsconfig.json (Optional but Recommended)
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)
Installation Summary
| Task | Command |
|---|---|
| Install TypeScript | npm install -g typescript |
| Check Version | tsc -v |
| Compile File | tsc file.ts |
| Initialize Config | tsc --init |
