Skip to content
Tutorials Center
My learning

Topics

TypeScript Tutorial

Learn TypeScript 7 from your first type annotation to generics, narrowing, utility, mapped and conditional types, classes and real projects. 96 lessons with type-checked code you run in your browser.

Start learning →

of lessons completed

Getting Started

  1. 1 Getting Started with TypeScript Learn what TypeScript is, how it adds static types to JavaScript, why teams rely on it, and write and run your first type-checked program in our editor.
  2. 2 How TypeScript Works See what the TypeScript compiler does - type-checking, emitting JavaScript and erasing types - and how tsc, Node type stripping and bundlers like Vite fit in.
  3. 3 Your First Types Add type annotations to variables, parameters and return values, and learn to read TypeScript errors - codes, line and column numbers and multi-line messages.
  4. 4 Variables and Scope in TypeScript Learn how TypeScript handles var, let and const, block and function scope, hoisting and the temporal dead zone, uninitialized variables and definite assignment.
  5. 5 Type Inference Learn how TypeScript infers types from values and returns, how let and const widen literals, best common types, contextual typing, and when annotations help.
  6. 6 The tsconfig.json File Understand tsconfig.json - strict, target, module, lib, outDir, noEmit, noUncheckedIndexedAccess, verbatimModuleSyntax and more - with recommended modern configs.
  7. 7 Strict Mode Explained Learn every flag behind TypeScript's strict option - strictNullChecks, noImplicitAny, strictFunctionTypes and more - each shown with the real bug it prevents.

Basic Types

  1. 8 Primitive Types Learn TypeScript's primitive types - string, number, boolean, bigint, symbol, null and undefined - plus literal values, typeof results and the wrapper-type trap.
  2. 9 Operators in TypeScript A practical guide to TypeScript operators - arithmetic, comparison, logical, bitwise, assignment, nullish and optional chaining, plus the type-aware operators typeof, instanceof, in, keyof, as and satisfies.
  3. 10 Arrays and Tuples Learn how TypeScript types arrays and tuples - T[] vs Array<T>, readonly arrays, fixed-length tuples, optional, rest and named elements, and readonly tuples.
  4. 11 Control Flow and Loops Learn if, switch, for, while, for...of, for...in and forEach in TypeScript, how loop variables are typed, why for...in keys are strings, labels and exhaustive switches.
  5. 12 Object Types Learn TypeScript object types - inline shapes, optional and readonly properties, nested objects, methods, excess property checks and index signatures.
  6. 13 Index Signatures and Record Type dynamic-key objects in TypeScript - string, number, symbol and template-literal index signatures, Record<K, V>, Map vs object, noUncheckedIndexedAccess.
  7. 14 any, unknown, never and void Learn why any switches off type checking, how unknown keeps untrusted data safe, what never means for exhaustive checks, and how void differs from undefined.
  8. 15 Union Types Learn TypeScript union types - writing A | B, what you can do with a union, narrowing with typeof and in, nullable types, literal unions and arrays of unions.
  9. 16 Literal Types and as const Learn TypeScript literal types - exact string, number and boolean types, literal unions, widening with let and const, as const and unions derived from values.
  10. 17 Type Aliases Learn TypeScript type aliases - naming object, union, tuple and function types, generic and recursive aliases like a JSON type, and when to name a type.
  11. 18 Interfaces Learn TypeScript interfaces - optional and readonly members, method signatures, extending interfaces, declaration merging and when to choose interface or type.
  12. 19 Enums Learn TypeScript enums - numeric and string enums, reverse mappings, const enums, what enums compile to, and why many teams prefer literal unions and as const objects.
  13. 20 Type Assertions and the Non-Null Operator Learn TypeScript type assertions - the as keyword, angle-bracket syntax, double assertions, the non-null ! operator, and how as differs from annotations and satisfies.

Functions

  1. 21 Typing Functions Learn to type TypeScript functions - parameter and return types, optional and default parameters, rest parameters, arrow functions, void and never return types.
  2. 22 Function Types and Callbacks Learn TypeScript function types - arrow-style type expressions, call signatures, typing callbacks and higher-order functions, contextual typing and function assignability.
  3. 23 Function Overloads Learn TypeScript function overloads - overload and implementation signatures, ordering rules, when overloads beat union types, and generic alternatives with type maps.
  4. 24 this, Parameter Destructuring and Type Predicates Learn to type this in TypeScript functions, destructured parameters with defaults, type predicates (x is T), assertion functions and inferred type predicates.
  5. 25 Optional, Default and Rest Parameters Master TypeScript parameter forms - optional vs undefined, defaults that depend on earlier parameters, options objects, rest tuples, labeled elements and spread calls.

Narrowing

  1. 26 Narrowing Learn how TypeScript narrows union types with control-flow analysis - typeof, truthiness, equality, in, instanceof, early returns and assignments - and the traps to avoid.
  2. 27 Discriminated Unions Model data safely with TypeScript discriminated unions - tag properties, switch narrowing, exhaustiveness checks with never, loading states and Result types.
  3. 28 Custom Type Guards Write your own TypeScript type guards - type predicates (x is T), validating unknown JSON, assertion functions, inferred predicates and schema libraries.

Objects and Classes

  1. 29 Object Types in Depth Go deeper into TypeScript object types - structural typing, assignability, optional vs undefined, readonly and Readonly, index signatures and intersection types.
  2. 30 Classes Learn TypeScript classes - typed fields and methods, constructors, parameter properties, readonly fields, strictPropertyInitialization and the definite assignment operator.
  3. 31 Access Modifiers and Private Fields Control access to class members in TypeScript - public, protected and private vs JavaScript #private fields, static members, getters, setters and the accessor keyword.
  4. 32 Inheritance and Abstract Classes Learn class inheritance in TypeScript - extends and super, the override keyword with noImplicitOverride, abstract classes and methods, and implementing interfaces.
  5. 33 Classes, Interfaces and Structural Typing Learn how TypeScript classes work with interfaces - implements, instance types vs typeof Class, constructor types like new () => T, abstract constructors and mixins.
  6. 34 Type Compatibility and Variance Learn when one TypeScript type is assignable to another - structural rules, excess property checks, function parameters, covariance, contravariance and branded types.
  7. 35 Readonly and Immutability Learn immutability in TypeScript - readonly properties, Readonly<T>, readonly arrays, ReadonlyMap and ReadonlySet, as const, deep readonly types, Object.freeze and safe updates.
  8. 36 Type Aliases vs Interfaces Compare TypeScript type aliases and interfaces - what each can express, declaration merging, extends vs intersections, error messages, performance and a simple rule of thumb.
  9. 37 Getters and Setters Learn TypeScript getters and setters - read-only and computed properties, validation, lazy values, differing getter and setter types, accessors in interfaces and the JSON pitfall.

Generics

  1. 38 Generics Learn TypeScript generics from scratch - why they beat any, generic functions, type argument inference, multiple type parameters, generic arrow functions and when not to use them.
  2. 39 Generic Constraints and Defaults Learn to limit TypeScript type parameters with extends and keyof, give them defaults, keep literal types with const type parameters and control inference with NoInfer.
  3. 40 Generic Interfaces, Classes and Types Build reusable TypeScript types with generics - Box<T>, generic interfaces and aliases, Result types, generic classes like Stack<T> and Repository<T>, and a typed EventEmitter.

Type Manipulation

  1. 41 keyof, typeof and Indexed Access Types Learn to derive TypeScript types from other types and from values - keyof T, typeof in type positions, indexed access T[K] and T[number], and keyof typeof for constants.
  2. 42 Built-in Utility Types Learn the TypeScript utility types Partial, Required, Readonly, Pick, Omit, Record, Exclude, Extract, ReturnType, Parameters, Awaited and NoInfer with examples.
  3. 43 Mapped Types Learn TypeScript mapped types - loop over keys with K in keyof T, add or remove readonly and ?, rename and filter keys with as, and build your own utilities.
  4. 44 Conditional Types Learn TypeScript conditional types - T extends U ? X : Y, how they distribute over unions, how to stop that with [T], and how infer extracts types.
  5. 45 Template Literal Types Learn template literal types - build string types from unions, use Uppercase and Capitalize, type event names and routes, and parse strings with infer.
  6. 46 Advanced Type-Level Programming Go further with TypeScript types - recursive DeepReadonly and Paths, variadic tuple types, branded types, in/out variance annotations, and knowing when to stop.
  7. 47 Recursive Types Learn TypeScript recursive types - self-referencing aliases for trees and JSON, recursive conditional and mapped types like DeepReadonly and Flatten, and depth limits.

Modules and Declarations

  1. 48 Modules Learn how TypeScript uses ES modules - named and default exports, import type, verbatimModuleSyntax, file extensions, and nodenext vs bundler resolution.
  2. 49 CommonJS Interop and esModuleInterop Understand CommonJS and ES module interop in TypeScript - esModuleInterop, allowSyntheticDefaultImports, import = require, export = and how default imports of CJS packages really work.
  3. 50 Declaration Files (.d.ts) Learn what TypeScript .d.ts declaration files are, how @types packages work, how to type a JavaScript library, and how declare global and augmentation work.
  4. 51 Namespaces Learn TypeScript namespaces - syntax, nested namespaces, aliases, what they compile to, declaration merging, and why ES modules replaced them in modern code.
  5. 52 Migrating JavaScript to TypeScript Move a JavaScript codebase to TypeScript gradually - allowJs, checkJs, JSDoc types, @ts-check, @ts-expect-error vs @ts-ignore, stricter checks and a plan.

Async and Errors

  1. 53 Promises and async/await Type asynchronous TypeScript code: Promise<T>, async return types, Awaited, typing Promise.all, allSettled, race and any, async callbacks and async iterators.
  2. 54 Error Handling Handle errors safely in TypeScript - unknown catch variables, narrowing, custom error classes, Error cause, never, and the Result pattern vs exceptions.
  3. 55 Iterators and Generators Type iteration in TypeScript - Iterable<T>, Iterator<T>, IteratorResult, Generator<T, R, N>, yield*, async generators and the ES2025 iterator helpers.
  4. 56 Result and Either Types for Errors Build a typed Result and Either in TypeScript - ok and err helpers, map, andThen, match, wrapping throwing code, async results, collecting many results and when to use them.

Modern Features

  1. 57 Decorators Learn standard TypeScript decorators - method, field, accessor and class decorators, context objects, logging, memoize, validation and legacy decorators.
  2. 58 using Declarations and Explicit Resource Management Clean up resources automatically in TypeScript with using and await using, Symbol.dispose, Symbol.asyncDispose, DisposableStack and SuppressedError.
  3. 59 The satisfies Operator Learn the TypeScript satisfies operator - validate objects against a type without losing their precise inferred types, and when to choose it over annotations or as.
  4. 60 What's New in TypeScript 5.x, 6.0 and 7.0 A guided tour of modern TypeScript - the headline features of every 5.x release, the 6.0 deprecations, the native Go compiler in 7.0 and how to upgrade safely.
  5. 61 Compiler API and Custom Transformers Learn how the TypeScript compiler API works with programs, source files, the AST, the type checker, visitors, transformers and codemods, with runnable AST and type-stripping examples.

TypeScript in Practice

  1. 62 TypeScript with Node.js Use TypeScript with Node.js - @types/node, typing fs, path and process, reading input, running .ts files with Node's type stripping, and building a small typed CLI tool.
  2. 63 TypeScript in the Browser (DOM) Use TypeScript with the DOM - enable lib dom, handle querySelector's Element | null, narrow to HTMLInputElement, type event listeners and fetch responses safely.
  3. 64 Typing APIs and JSON Data Model API responses in TypeScript, validate unknown JSON at runtime, infer types from schemas like Zod, generate types from OpenAPI and build a generic, type-safe fetch wrapper.
  4. 65 TypeScript with React Learn how to use TypeScript with React - typing props, children, state, events, refs, reducers, context and generic components, with the patterns teams use every day.
  5. 66 TypeScript with Vue, Angular and Express See how TypeScript works in Express, Vue and Angular - typed route handlers and params, defineProps and defineEmits, Angular dependency injection, and project templates.
  6. 67 TypeScript with NestJS Learn how NestJS uses TypeScript - modules, controllers, providers, dependency injection, decorators, DTO validation and testing - with runnable stand-ins that show how it works.
  7. 68 Typed Backends: Fastify, Hono and Koa Compare Fastify, Hono and Koa in TypeScript - typed route generics, schemas and type providers, context typing, middleware and testing - with runnable stand-ins of each idea.
  8. 69 Tooling: Linting, Testing and Building Set up a professional TypeScript toolchain - ESLint with typescript-eslint, Prettier, Vitest and type tests, CI type checks, and building apps and libraries.
  9. 70 Scaling TypeScript: Project References and Build Performance Scale TypeScript to monorepos - project references, composite and incremental builds, tsc --build, isolatedDeclarations, skipLibCheck and finding slow types.
  10. 71 Best Practices and Common Mistakes Write TypeScript that stays safe as it grows - strict settings, unknown at boundaries, inference, unions, readonly data, fewer assertions, and the six most common errors.
  11. 72 Debugging TypeScript Learn to debug TypeScript with source maps, VS Code launch configurations, node --inspect, tsx and ts-node, breakpoints, logpoints and how to read stack traces and type errors.
  12. 73 Testing TypeScript with Jest and Vitest Learn to test TypeScript code with Jest (ts-jest) and Vitest - setup, typed assertions, typed mocks and spies, testing types with expectTypeOf, and what type checking does not cover.
  13. 74 Validating Data with Zod and Type Inference Use Zod schemas to validate JSON, form input and environment variables at runtime, derive types with z.infer, handle errors and transform data into clean domain values.
  14. 75 Monorepos and Shared Types Share TypeScript types between apps in one repository with npm workspaces, shared packages, project references, path mapping, exports and how to keep builds fast and types consistent.
  15. 76 Testing Types Write tests for TypeScript types themselves with Equal and Expect helpers, @ts-expect-error, Vitest expectTypeOf, tsd and type-level regression tests for utility types and library APIs.

Projects

  1. 77 Project: Typed To-Do CLI Build a command-line to-do app in TypeScript - parse commands into a discriminated union, keep a typed store, format a table and add undo with an immutable reducer.
  2. 78 Project: Inventory with Generics Build a typed inventory in TypeScript - a generic Repository, DTO types made with Omit, Partial and Pick, validation of unknown JSON with type guards, and reports.
  3. 79 Project: Type-Safe Event Emitter Build a fully typed event emitter in TypeScript - an event map, mapped listener types, on/off/once, disposable subscriptions, async listeners and type tests.
  4. 80 Project: State Machine Build state machines in TypeScript - a traffic light with a checked transition table, a generic machine with const type parameters, and an order workflow.
  5. 81 Project: Typed API Client Build a type-safe API client in TypeScript - an endpoint map, typed path params, a generic request function, runtime response validation, retries and Result errors.
  6. 82 Project: Type-Safe DOM Widgets Build three typed browser widgets in TypeScript - a counter, a show/hide password toggle and a drag-and-drop list - with testable logic and DOM-shaped interfaces.
  7. 83 Project: Task Board Build a Kanban-style task board in TypeScript - a typed task model, columns with WIP limits, filters, a storage adapter with validation, and undo/redo.
  8. 84 Project: Typed Calculator Build a calculator in TypeScript - tokenize and parse expressions into a typed tree, evaluate with a Result type, then drive a keypad with a typed reducer and DOM-shaped bindings.
  9. 85 Project: Password Generator and Unicode Finder Build two small tools in TypeScript - a secure password generator using crypto.getRandomValues with typed options and entropy, and a Unicode finder that inspects code points and graphemes.
  10. 86 Project: Typing Speed Test Build a typing speed test in TypeScript - score text per character, compute WPM and accuracy, run a timed session state machine with an injectable clock, and bind it to DOM events.
  11. 87 Project: Pixel Art Maker Build a pixel art editor in TypeScript - an immutable grid with a typed palette, drawing tools (pencil, line, flood fill), generic undo and redo, SVG and JSON export, and canvas-shaped rendering.
  12. 88 Project: Typed Quiz App Build a quiz engine in TypeScript - model single, multiple, true/false and text questions as a discriminated union, score them with a mapped type, run a session and render results.
  13. 89 Project: Contact Manager Build a contact manager in TypeScript - a generic repository with create, read, update and delete, field validation with mapped types, search, sorting and persistence through a storage interface.
  14. 90 Project: Tic Tac Toe Build tic tac toe in TypeScript - a fixed-size tuple board, win detection from constant lines, a discriminated game state, an unbeatable minimax AI and a click-driven UI binding.
  15. 91 Project: Canvas Animation Build a canvas particle animation in TypeScript - typed vectors and particles, a physics step, a frame loop with an injectable scheduler and fixed time step, and a canvas-shaped renderer.
  16. 92 Project: React Quiz with TypeScript Build a quiz in React with TypeScript - a state machine reducer with a discriminated union, typed component props, event handler types and a live React demo you can edit.

Practice and Review

  1. 93 TypeScript Cheat Sheet A dense TypeScript 7 reference: types, unions, narrowing, functions, classes, generics, utility, mapped and conditional types, tsconfig and error codes.
  2. 94 TypeScript Programs: 40 Classic Examples 40 classic TypeScript programs with output: primes, Fibonacci, palindromes, Roman numerals, sorting, stacks, trees, LRU caches and typed utilities.
  3. 95 TypeScript Practice Exercises 30 graded TypeScript exercises with solutions: annotations, narrowing, type guards, classes, generics, utility, mapped, conditional and template literal types.
  4. 96 TypeScript Interview Questions 51 TypeScript interview questions with answers plus 5 code-reading puzzles: types, unions, narrowing, generics, utility, mapped and conditional types, TS 7.