TypeScript Tutorial

1. What is TypeScript really? (The Honest Explanation)

TypeScript is JavaScript + superpowers.

More precisely:

  • TypeScript = JavaScript + static types + better developer experience
  • You write code that looks almost like modern JavaScript
  • But you add type annotations → the computer checks your code before it runs
  • After checking, TypeScript compiler converts your .ts file → normal .js file
  • Browsers / Node.js never see TypeScript — they only run the generated JavaScript

Most important sentence you should remember today:

TypeScript doesn’t add new runtime features (almost). It adds safety checks before the program runs.

2. Why should you learn TypeScript in 2025–2026?

Real-world reasons:

  • Almost all new big React, Angular, Next.js, NestJS projects use TypeScript
  • Big companies (Google, Microsoft, Meta, Vercel, Shopify…) mostly write TypeScript
  • You catch 70–90% of silly bugs before the app even starts
  • Much better autocompletion in VS Code / WebStorm
  • Refactoring large codebases becomes 10× safer
  • Teamwork becomes much easier — new developers understand the code faster

3. Let’s Set Up TypeScript (5 minutes)

Option 1: Quick playground (recommended for learning now) Go to: https://www.typescriptlang.org/play You can write TypeScript right in the browser — no installation needed.

Option 2: Local setup (do this later today or tomorrow)

Bash

Now open tsconfig.json and make sure it has at least these useful settings:

JSON

Create file src/index.ts and write your first code.

4. Your Very First TypeScript Code

Let’s write JavaScript first — then improve it with TypeScript.

JavaScript version (can have bugs):

JavaScript

Same code — now with TypeScript:

TypeScript

See the magic?

As soon as you write : string, VS Code / TypeScript tells you:

Argument of type ‘number’ is not assignable to parameter of type ‘string’.

You catch the bug before running the code.

5. Basic Types (The Building Blocks)

Here are the most common types you will use every day:

TypeScript

6. Arrays & Tuples

TypeScript

7. Objects — Two Main Ways

Way 1: Inline type annotation

TypeScript

Way 2: Create reusable type / interface (Recommended!)

TypeScript

Difference — type vs interface (quick version)

TypeScript

Most people use interface for objects, type for unions / primitives / complex combinations.

8. Functions — Very Important

TypeScript

9. Union Types & Type Narrowing

TypeScript

10. Quick Summary Table (Keep this in mind)

Feature Syntax Example Purpose
Basic type : string, : number Tell what value is allowed
Array string[] or Array<string> List of same type
Tuple [string, number] Fixed length & fixed types
Object interface User { name: string } Describe shape of object
Union string number
Optional age?: number Property may not exist
Readonly readonly id: number Cannot re-assign
Literal type status: "active" "inactive"

Homework for Today

  1. Go to https://www.typescriptlang.org/play
  2. Try to write these functions with types:
TypeScript
  1. Make one intentional mistake (pass number instead of string) and see the red underline

Tomorrow we can go deeper: classes, generics, enums, type guards, React with TypeScript, etc.

Any doubt? Want to focus on any particular part right now? Just tell me — we’ll zoom in! 😄