Free course · 11 lessons · Beginner

TypeScript Fundamentals: Types, Generics and Real-World Patterns

Learn TypeScript from your first typed program to production patterns: strict mode and inference, objects and interfaces, unions with narrowing and discriminated unions, functions and overloads, arrays, tuples and as const, classes, generics with constraints, utility, mapped and conditional types, async code and typed error handling, modules and tsconfig, and a validation pipeline capstone. Every example is type-checked with the TypeScript compiler in strict mode and run, with its real output shown.

Start the course

1. TypeScript Basics: Types, Narrowing and Functions

Add types to JavaScript and let the compiler catch mistakes: inference, objects and interfaces, unions with narrowing, functions, arrays and tuples, and classes.

  1. Hello, TypeScript: Types, Inference and Strict Mode — Write your first typed program, see how inference removes most annotations, use unknown instead of any, and learn how the compiler reports mistakes before the code runs.
  2. Objects, Interfaces and Type Aliases — Describe the shape of objects with interfaces and type aliases, mark properties optional or readonly, use index signatures, and understand how TypeScript compares object types.
  3. Unions, Narrowing and Discriminated Unions — Model values that can be one of several types, narrow them with typeof, in and equality checks, and use discriminated unions with exhaustive checking to handle every case.
  4. Functions: Parameters, Callbacks and Overloads — Type function parameters and return values, use optional, default and rest parameters, describe callbacks with function types, and write overloads for functions with several call shapes.
  5. Arrays, Tuples, Readonly Data and as const — Type arrays and tuples, protect data with readonly, use as const to infer exact literal types, and replace enums with literal unions and lookup objects.
  6. Classes: Modifiers, Interfaces and Abstract Types — Write classes with typed properties, parameter properties and access modifiers, implement interfaces, use abstract classes and getters, and understand private versus #private.

2. Generics, Utility Types and Real-World TypeScript

Write reusable generic code, transform types with utility, mapped and conditional types, handle async code and errors safely, configure a project, and put it together in a typed pipeline.

  1. Generics: Reusable, Type-Safe Code — Write functions, interfaces and classes that work with many types without losing type information, constrain type parameters with extends and keyof, and use defaults.
  2. Utility, Mapped and Conditional Types — Transform existing types with Partial, Required, Pick, Omit, Record and ReturnType, build your own mapped and conditional types, and use template literal types.
  3. Async Code and Typed Error Handling — Type promises and async functions, run tasks in parallel with Promise.all, handle thrown values safely as unknown, and model failures explicitly with a Result type.
  4. Modules, tsconfig and Working with JavaScript — Organise code with ES modules and type-only imports, choose the tsconfig options that matter, validate objects with satisfies, and migrate a JavaScript project gradually.
  5. Capstone: A Typed Order Pipeline — Combine everything: validate untrusted input with type guards, model results with discriminated unions, process orders through a generic pipeline, and report totals with derived types.

Was this page helpful?