Chapter 2: TypeScript Getting Started

πŸš€ TypeScript – Getting Started (Step-by-Step Guide for Beginners)

Now that you understand what TypeScript is, let’s learn how to start using TypeScript on your computer β€” like a real teacher explaining in class 😊

We will cover:

  1. What you need before starting

  2. Installing TypeScript

  3. Writing your first TypeScript program

  4. Compiling TypeScript

  5. Using tsconfig.json

  6. Running TypeScript in browser and Node.js

πŸ“Œ 1️⃣ What You Need Before Starting

Since TypeScript converts into JavaScript, you need:

βœ… 1. Node.js

TypeScript uses Node Package Manager (npm) to install.

Install:
πŸ‘‰ Node.js
Download from official website and install.

To check installation:

If version shows β†’ installed successfully βœ…

πŸ“Œ 2️⃣ Installing TypeScript

After installing Node.js, open:

  • Command Prompt (Windows)

  • Terminal (Mac/Linux)

Then type:

This installs TypeScript globally.

To check:

If version appears like:

Then TypeScript installed successfully πŸŽ‰

Let’s create a project step by step.

πŸ§‘β€πŸ« Step 1: Create a Folder

Create a new folder:

Open this folder in VS Code (recommended editor).

πŸ‘‰ Visual Studio Code

πŸ§‘β€πŸ« Step 2: Create a TypeScript File

Create a file:

(.ts extension means TypeScript file)

πŸ§‘β€πŸ« Step 3: Write Code

Inside app.ts write:

πŸ“Œ 4️⃣ Compile TypeScript to JavaScript

TypeScript cannot run directly.

You must compile it using:

Now you will see a new file:

The compiler converted TypeScript β†’ JavaScript.

Now run it using Node:

Output:

πŸŽ‰ Congratulations! Your first TypeScript program works.

Let’s change code:

Now run:

You will get error like:

πŸ‘‰ This is the power of TypeScript.
It catches error BEFORE running program.

πŸ“Œ 6️⃣ Using tsconfig.json (Professional Way)

When working on real projects, we don’t compile one file at a time.

We create a configuration file.

πŸ§‘β€πŸ« Step 1: Create tsconfig.json

Inside project folder, run:

This creates:

Example content:

What These Mean:

  • target β†’ JavaScript version

  • module β†’ module system

  • strict β†’ strict type checking

  • outDir β†’ output folder for JS files

Now just run:

It will compile all .ts files.

πŸ“Œ 7️⃣ Running TypeScript with Node.js (Backend)

TypeScript is commonly used with:

πŸ‘‰ Node.js

Example:

Compile and run using Node.

You cannot directly use .ts file in HTML.

Example:

index.html

πŸ“Œ 9️⃣ Project Folder Structure (Best Practice)

Professional developers follow this structure.

πŸ“Œ 1️⃣0️⃣ Optional: Using ts-node (Advanced Shortcut)

Instead of compiling manually, you can install:

Then directly run:

No need to manually compile.

🧠 Important Concepts While Getting Started

When learning TypeScript, focus on:

  • Types (string, number, boolean)

  • Functions with types

  • Interfaces

  • Arrays

  • Objects

  • Strict mode

🎯 Small Real Project Example

Let’s build simple calculator.

Compile and run β†’ Clean and error-free.

🏁 Final Summary (Exam Ready Definition)

Getting Started with TypeScript means installing TypeScript using Node.js, creating .ts files, compiling them into JavaScript using the TypeScript compiler (tsc), and running the generated JavaScript file in browser or Node.js environment.

If you want, I can next explain:

  • πŸ”Ή TypeScript Project Setup with React

  • πŸ”Ή TypeScript Folder Structure for Large Projects

  • πŸ”Ή TypeScript vs JavaScript practical difference

  • πŸ”Ή TypeScript Interview Questions

  • πŸ”Ή Complete TypeScript syllabus roadmap

Just tell me 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *