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
nullandundefined - 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:
- JavaScript objects, functions and modules
null,undefinedand optional chaining (?.)- TypeScript type annotations for objects and arrays
- Running a
.tsfile with Node.js - Reading the checker’s errors
- A
typeofcheck on anunknownvalue - A union of two primitives, such as
string | number
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.