TypeScript from the ground up
Say what your code means
- Beginner
- 13 chapters
- 193 min read
A hands-on first course in TypeScript, from your first annotation to a small typed app: every idea comes with a page you can change and run, with a short quiz at the end of each chapter.
What You'll Learn
- Annotate values and functions, and say what they promise
- Let the compiler infer what you do not need to write
- Describe objects with interfaces and type aliases
- Narrow union types safely instead of reaching for any
- Write generic functions that keep their types
- Type the DOM: queries, elements and events
- Derive types from types with Partial and Record
- Use strict mode, and know what it turns on
Prerequisites
- The JavaScript course on this site, or the same ground: variables, functions, arrays, objects, and the DOM
- No TypeScript experience needed; the course starts at the first annotation
Course Content
- 01How TypeScript worksNot started
JavaScript plus type annotations: what the annotations are for, why the browser never sees them, and what the preview does with your code.
- 02Annotations and inferenceNot started
When to write the type out and when to let TypeScript work it out: inference, what a name that never changes is worth, and where the compiler has to be told.
- 03Functions and their signaturesNot started
A function signature is a promise in two directions: what the caller may pass in, and what the function will hand back.
- 04Objects and interfacesNot started
Describing the shape of an object once — with an interface — and having every function that takes it, and every object that claims to be it, checked against that description.
- 05Unions and narrowingNot started
A value that may be one of two things: how to say so with a union, and how the compiler follows your checks until only one possibility is left.
- 06Lists and genericsNot started
Typed lists that keep their element type through every map and filter, and the one idea behind them: a function that says "for any type" without losing track of which.
- 07Classes and interfacesNot started
Typed state, methods that say what they take, `private` for what is nobody else’s business, and an interface a class can sign.
- 08Exact valuesNot started
A type can name one exact value: a set of allowed strings instead of a loose one, and `as const` for the lists and objects that should never be edited by accident.
- 09Telling the cases apartNot started
A union of objects with one field that says which one it is, a switch the compiler follows, and the check that proves every case was handled.
- 10The page, typedNot started
Queries that know what they found, events that know what happened, and the one check the compiler insists on before any element is touched.
- 11Types built from typesNot started
Partial and Record: shapes derived from a shape you already have, so an update payload and a lookup table cannot drift from the thing they describe.
- 12The compiler and its settingsNot started
tsconfig, strict mode and what it turns on, the difference between `any` and `unknown`, and where the type checker sits in a real build.
- 13A small typed appNot started
Everything at once, on a page: a shape for each item, a typed list, functions with signatures, and a DOM query the compiler can vouch for.
