Frontend track

TypeScript Tutorial

JavaScript with static types. Catch bugs early and write self-documenting code.

IntermediateExamples target TypeScript 5.x with "strict": true.
0/29 complete
Topics
29
Full lessons
29
Est. hours
~5
Interview Qs
26

Overview

TypeScript is a superset of JavaScript that adds a static type system. The TypeScript compiler checks your code and then emits plain JavaScript, so it runs anywhere JavaScript runs.

Types catch whole categories of bugs before your code ever runs and make editors far more helpful with autocompletion and refactoring.

What you will learn

  • Annotate values, functions and objects with types
  • Model data with interfaces, unions and generics
  • Narrow types safely with type guards
  • Configure tsconfig.json for real projects

Prerequisites

You will get the most from this track if you already know:

Learning path

The recommended sequence, from beginner to advanced. Each stage builds on the one before.

  1. 1Getting Started · 5 topics · Beginner
    Introduction to TypeScript · JavaScript vs TypeScript · Installation and Configuration · Basic Types · Type Inference
  2. 2Modelling Data · 6 topics · Beginner → Intermediate
    Arrays and Tuples · Objects and Type Aliases · Interfaces · Union and Intersection Types · Literal Types · Enums
  3. 3Functions · 3 topics · Intermediate
    Functions and Function Types · Optional and Default Parameters · Generics
  4. 4Classes · 4 topics · Intermediate
    Classes · Access Modifiers · Inheritance · Abstract Classes
  5. 5Advanced Types · 4 topics · Intermediate → Advanced
    Type Narrowing · Type Guards · Utility Types · keyof and typeof
  6. 6Projects · 7 topics · Advanced
    Modules · tsconfig.json · Strict Mode · Async Programming · TypeScript with React · TypeScript with Angular · Practical Projects

Complete topic list

29 topics
1

Getting Started

5 topics
  1. Introduction to TypeScriptBeginner5m
  2. JavaScript vs TypeScriptBeginner5m
  3. Installation and ConfigurationBeginner5m
  4. Basic TypesBeginner5m
  5. Type InferenceBeginner5m
2

Modelling Data

6 topics
  1. Arrays and TuplesBeginner5m
  2. Objects and Type AliasesBeginner5m
  3. InterfacesIntermediate5m
  4. Union and Intersection TypesIntermediate5m
  5. Literal TypesIntermediate5m
  6. EnumsIntermediate6m
3

Functions

3 topics
  1. Functions and Function TypesIntermediate5m
  2. Optional and Default ParametersIntermediate5m
  3. GenericsIntermediate5m
4

Classes

4 topics
  1. ClassesIntermediate5m
  2. Access ModifiersIntermediate5m
  3. InheritanceIntermediate5m
  4. Abstract ClassesIntermediate5m
5

Advanced Types

4 topics
  1. Type NarrowingIntermediate6m
  2. Type GuardsIntermediate5m
  3. Utility TypesAdvanced5m
  4. keyof and typeofAdvanced5m
6

Projects

7 topics
  1. ModulesAdvanced5m
  2. tsconfig.jsonAdvanced5m
  3. Strict ModeAdvanced5m
  4. Async ProgrammingAdvanced6m
  5. TypeScript with ReactAdvanced6m
  6. TypeScript with AngularAdvanced6m
  7. Practical ProjectsAdvanced6m

Code example

A taste of the track, from Introduction to TypeScript.

TypeScriptA bug JavaScript misses, TypeScript catches Illustrative
interface User {
  name: string;
  email: string;
}


function sendWelcome(user: User): string {
  return `Welcome, ${user.name}! We sent a mail to ${user.emial}`;
  //                                                   ~~~~~
  // ✗ Error: Property 'emial' does not exist on type 'User'. Did you mean 'email'?
}


sendWelcome({ name: 'Asha' });
//          ~~~~~~~~~~~~~~~~
// ✗ Error: Property 'email' is missing in type '{ name: string; }'
Expected output
The code does not compile. TypeScript reports both bugs — the misspelled property and the missing email — before the code ever runs. Plain JavaScript would have printed “…mail to undefined”.

Practice exercises

Show all 29 exercises
Objects and Type Aliases

Create a type Address (street, city, pin, optional landmark) and a type Customer with a readonly id, name and an array of addresses.

Interfaces

Create an interface Shape with area(): number. Create Circle and Rectangle classes that implement it, and a function totalArea(shapes: Shape[]).

Union and Intersection Types

Model a payment method that is either a card (cardNumber, expiry) or UPI (upiId), with a "method" discriminator, and write describe(p) returning a string for each.

Literal Types

Create a Theme type from the array const themes = ["light", "dark", "system"] and a function setTheme(t: Theme).

Enums

Create a string enum LogLevel (Debug, Info, Warn, Error) and a function log(level, msg) that prefixes the message with the level value.

Functions and Function Types

Write a type Validator = (value: string) => string | null (null means valid) and a function validateAll(value, validators: Validator[]) that returns the first error or null.

Optional and Default Parameters

Write formatDate(date: Date, options?) where options has optional locale (default "en-IN") and withTime (default false).

Generics

Write a generic function last<T>(items: T[]): T | undefined that returns the final element.

Classes

Write a class BankAccount with a readonly accountNumber, a private balance starting at 0, deposit(amount) and a balance getter. Reject negative deposits.

Access Modifiers

In class Car, make engineNumber private readonly, speed protected and model public. Add a static wheels = 4.

Inheritance

Create class AppError extends Error with a statusCode, and NotFoundError extends AppError that always uses 404 and a message like "User not found".

Abstract Classes

Create abstract class Employee with name, an abstract monthlyPay(): number and a normal method payslip() returning "<name>: ₹<pay>". Implement FullTime (salary/12) and Contractor (hours × rate).

Type Narrowing

Write describe(x: string | string[] | undefined) that returns "nothing", the string itself, or the items joined with commas.

Type Guards

Write isNonEmptyString(x: unknown): x is string that returns true only for strings with at least one non-space character, and use it to filter ["a", "", 3, " b "].

Utility Types

Given interface Product { id: number; name: string; price: number; stock: number }, create: ProductForm (no id), ProductPatch (all form fields optional) and StockMap (Record of product name to stock).

keyof and typeof

Write a generic getProp<T, K extends keyof T>(obj: T, key: K): T[K] and show that getProp(user, "age") returns number for user = { name: "Asha", age: 24 }.

Modules

You install the JS library "slugify-lite" and get “Could not find a declaration file”. Write a declaration for its default export slugify(text: string): string.

tsconfig.json

Write a tsconfig.json for a Node.js API that compiles src/ to dist/ with strict checks and source maps.

Strict Mode

Fix all strict errors: function firstUpper(list) { return list[0].toUpperCase(); }

Async Programming

Write getJson<T>(url: string, fallback: T): Promise<T> that returns the parsed JSON, or the fallback if the request fails for any reason.

TypeScript with React

Create a typed Avatar component with props src (string), alt (string), size ("sm" | "md" | "lg", default "md") and optional onClick.

TypeScript with Angular

Write a typed UserService with a method getById(id: number): Observable<User> using HttpClient, where User has id, name and email.

Practical Projects

Project 2 starter: write sortBy<T>(items: T[], key: keyof T, dir: "asc" | "desc" = "asc"): T[] that returns a sorted copy.

Common interview questions

Frequently asked questions

Does TypeScript run in the browser?
Browsers run JavaScript. TypeScript is compiled (or type-stripped) to JavaScript first, usually by your build tool.