Certainly! Here’s the full rewritten article with an SEO-optimized title and structure based on your instruction:
🚀 TypeScript Installation & Hello World – Get Started with TS in Minutes (2025 Guide)
🧲 Introduction – Get Up and Running with TypeScript
TypeScript enhances JavaScript with static typing, tooling, and scalability. Whether you’re building modern web apps or backend services, setting up TypeScript is the first step toward writing safer, maintainable code.
🎯 In this guide, you’ll learn:
- How to install TypeScript using npm
- How to create a configuration file (
tsconfig.json
) - How to write and compile your first “Hello World” program
💾 Step 1: Install Node.js (Required)
TypeScript runs on Node.js. First, download and install Node.js from the official site:
To verify installation, open your terminal and run:
node -v
npm -v
📦 Step 2: Install TypeScript via NPM
Once Node.js is installed, use npm to install TypeScript globally:
npm install -g typescript
✅ Verify the installation:
tsc -v
You should see the TypeScript compiler version (e.g., Version 5.x.x
).
🗂️ Step 3: Create a TypeScript Project Folder
Organize your files by creating a new project directory:
mkdir typescript-demo
cd typescript-demo
🧾 Step 4: Initialize TypeScript Configuration
Generate a basic tsconfig.json
file:
tsc --init
This file controls how TypeScript compiles your code.
Sample config excerpt:
{
"compilerOptions": {
"target": "ES6",
"outDir": "./dist",
"rootDir": "./src",
"strict": true
}
}
Create the required folder structure:
mkdir src
📝 Step 5: Write Your First TypeScript File
Inside the src
folder, create a file named index.ts
:
let message: string = "Hello, TypeScript!";
console.log(message);
🧠 Explanation:
message
is a typed variable of typestring
.console.log
prints the message to the terminal.
🛠️ Step 6: Compile TypeScript to JavaScript
Compile the .ts
file into JavaScript using:
tsc
It creates dist/index.js
based on your tsconfig.json
settings.
▶️ Step 7: Run the Compiled Code
Use Node.js to run your output JavaScript:
node dist/index.js
✅ Output:
Hello, TypeScript!
Congratulations! You’ve successfully set up and executed your first TypeScript program.
📌 Summary – Recap & Next Steps
You’ve installed TypeScript, created a project, and compiled your first “Hello World” program. This setup is the foundation for larger projects using modern frameworks like Angular, React, or Node.js.
🔍 Key Takeaways:
- TypeScript is installed via npm using
npm install -g typescript
. tsconfig.json
controls TypeScript behavior.- The
tsc
command compiles.ts
files into JavaScript. - Your first TypeScript program can be executed using Node.js.
⚙️ Real-World Relevance:
This setup is essential for frontend and backend TypeScript projects. From here, you can begin learning advanced types, modules, and tooling support.
❓ FAQs – TypeScript Installation & Hello World
❓ Do I need Node.js to run TypeScript?
✅ Yes, Node.js is required to run the TypeScript compiler (tsc
) and to execute compiled JavaScript files.
❓ What command compiles TypeScript files?
✅ Use tsc
to compile .ts
files to .js
.
❓ Where does TypeScript output the compiled files?
✅ By default, output goes to the same directory. You can configure it using outDir
in tsconfig.json
.
❓ Can I use TypeScript with frameworks like React or Angular?
✅ Absolutely! Most modern frameworks support TypeScript out of the box.
Share Now :