Loading video player…

Modeling Data With TypeScript (Overview)

Welcome to Modeling Data With TypeScript. This course is about types that rule out the states your data should never be in.

Its story is Harbor Line, a family-run ferry with two boats that sail from Port Wren to three islands. The line’s old JavaScript kept every crossing in one object with a dozen optional properties. When a gale warning canceled the 11:20 crossing to Heron Key, the record got a reason but kept its gate, so the old departures board printed it as boarding: 11:20 Puffin to Heron Key: boarding at gate B.

In this course, you’ll give each crossing state and each kind of ticket its own type, then build the departures board, the ticket desk, and the fares on them. Your board reads each crossing’s state first, so the same crossing comes out as 11:20 Puffin to Heron Key: canceled (gale warning).

What You’ll Learn

By the end of this course, you’ll be able to:

  • Model data with named types, unions and literal types so impossible combinations can’t be written
  • Narrow a union safely
  • Handle null and undefined
  • Make the checker report a case that isn’t handled

The course ends with a project on Harbor Line’s departures and bookings. When the line adds a full state for sold-out crossings, the checker lists both places in your code that still need it, the departures board and the ticket desk.

Before You Start

You need to be comfortable with:

This is the second course in the TypeScript for JavaScript Developers path, and it picks up where the path’s first course leaves off. If you’re arriving here directly, you’re welcome to start with this course. If those TypeScript basics are new to you, then the path’s first course covers them.

The examples run on Node.js 26.13.1 and are checked with TypeScript 7.0.2.

How the Course Works

Text lessons and short videos alternate with coding exercises that run in your browser. The exercises’ tests run your code but can’t run the type checker, so you’ll also work in your own harbor-line folder and run npm run check there. After the project, you’ll explain your types in a chat with the mentor, and a quiz and a summary close the course.

Next comes the text lesson Naming Shapes With type and interface, where you’ll set up that folder.

Download

Course Slides (.pdf)

572.7 KB
Download

Sample Code (.zip)

13.0 KB

00:00 Welcome to Modeling Data With TypeScript. It’s about types that rule out the states your data should never be in. Here’s a first taste, from Harbor Line, a family-run island ferry.

00:12 Its old board showed a canceled crossing as boarding.

00:16 Your board will read the state first, so the same crossing comes out canceled.

00:23 Harbor Line runs two boats from Port Wren to three islands. Its old code kept every crossing in one object with a dozen optional properties. This canceled crossing got a reason but kept its gate, so the old board printed boarding.

00:38 You’ll give each crossing state and each kind of ticket its own type, then build the board, the ticket desk and the fares on them. You’ll model data with named types, unions and literal types so impossible combinations can’t be written.

00:56 You’ll narrow a union safely, checking which kind of value you’ve got first. You’ll handle null and undefined, and make the checker report a case that isn’t handled.

01:07 In the project, Harbor Line adds a full state for sold-out crossings, and the checker lists both places that need it. You need JavaScript objects, functions and modules, plus null, undefined and optional chaining.

01:23 From TypeScript: type annotations for objects and arrays, running a file with Node, and reading the checker’s errors. Node 26 runs the examples and TypeScript 7 checks them.

01:38 Text lessons and short videos alternate with coding exercises in your browser. Their tests run your code but can’t run the type checker, so you’ll also work in your own Harbor Line folder and check it there.

01:51 After the project, you’ll explain your types in a chat with the mentor. A quiz and a summary close the course. Next comes Naming Shapes With type and interface, where you set up that folder.

Become a Member to join the conversation.