TypeScript Course: Type Your JavaScript Code with Confidence

TypeScript is an intermediate-level course of 5 lessons (about 2 h 29 min), with 15 exercises and 15 quiz questions. Prerequisites: Asynchronous JavaScript (Promises, fetch, APIs). Exercises run in the browser, with nothing to install.

  • Front-end
  • Intermediate
  • 5 lessons
  • 2 h 29 min
  • 15 exercises
  • Exercises run in the browser

The course in brief

This course takes you from JavaScript to TypeScript so you can write more reliable, easier-to-maintain code. You will learn to describe your data with interfaces and unions, write generic functions, model state with discriminated unions and validate external data at runtime. The exercises combine TypeScript code checked by the compiler and JavaScript logic tested automatically.

What you will be able to do

  • Set up a TypeScript project in strict mode and understand what the compiler does
  • Describe data with interfaces, aliases, literal unions and optional properties
  • Write generic functions and constrained generic types with extends and keyof
  • Model state and actions with discriminated unions checked with never
  • Derive types with Partial, Pick, Omit, Record, as const and satisfies
  • Validate external data with type guards and write a typed fetch client

Syllabus: 5 lessons

    • Explain what TypeScript brings compared to JavaScript
    • Annotate variables, parameters and return values with basic types
    • Rely on inference and understand strict mode

    TypeScript primitive typesType inferenceStrict mode and tsconfig

  1. 02

    Objects, Interfaces, Unions and Narrowing

    18 min
    • Describe the shape of an object with interface or type
    • Use optional and readonly properties
    • Combine types with unions and narrow them

    Interfaces and type aliasesUnions and literal typesType narrowing

  2. 03

    Typed Functions and Generics

    18 min
    • Type parameters, return values, callbacks and optional parameters
    • Write reusable generic functions
    • Constrain a generic with extends and keyof

    Function typesGenericskeyof and indexed types

  3. 04

    Discriminated Unions and Utility Types

    18 min
    • Model state with discriminated unions
    • Guarantee the exhaustiveness of a switch with never
    • Derive types with Partial, Pick, Omit, Record, ReturnType and as const

    Discriminated unionsUtility typesas const and satisfies

  4. 05

    Typing the DOM and API Data

    20 min
    • Manipulate the DOM in a typed way (querySelector, events)
    • Validate external data at runtime with type guards
    • Write a safe generic fetch client

    DOM typesType guardsTyped fetch client

Final project

A Typed API Client for a Mini Task Manager

Migrate a small task manager written in JavaScript to strict TypeScript. Model the tasks and the interface actions with discriminated unions, derive the creation and update types with utility types, and write a generic API client that validates every response before exposing it to the rest of the application. The DOM is manipulated without non-null assertions.

Deliverables

  • A tsconfig.json in strict mode and code that passes tsc --noEmit with no errors
  • The types Tache, TacheCreation, TacheMaj and the Action union, with an exhaustive reducer checked with never
  • An api.ts module exposing chargerJSON<T> and type guards for each resource
  • A typed DOM interface (add form, list, filters) with no any and no ! operator
  • Tests of the pure logic (reducer, validators)

Assessment criteria

  • No explicit or implicit any
  • Impossible states made unrepresentable by the types
  • External data is received as unknown and validated
  • Derived types automatically follow the base model
  • Readability: annotations at the boundaries, inference elsewhere

Frequently asked questions

Do I need to know JavaScript well before learning TypeScript?

Yes. TypeScript adds types to JavaScript without changing how it works. This course assumes you are comfortable with functions, objects, arrays and asynchronous code (promises, async/await).

Does TypeScript check data at runtime?

No. Types are checked at compile time and then erased. For external data (APIs, forms, local storage), you need to validate it at runtime with type guards or a schema library, which the course teaches.

Interface or type: which should I choose?

To describe an object, both work. type is needed for unions and aliases of primitive types; interface can be extended and merged. What matters is adopting a consistent convention across the project.

Is this course up to date with the latest TypeScript versions?

Yes. It uses TypeScript 7, the native compiler: same tsc command, strict mode by default and obsolete options removed. The language concepts (including satisfies) remain valid with versions 5 and 6, which you will come across in existing projects.

This course, told for your job

Say what you want to be able to do: “TypeScript” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.