TypeScript: From Basics to Expert
Four levels, twelve lessons, fully type-checked in the browser
TypeScript is JavaScript with a type system bolted on top and removed again before the code runs. You write annotations, a compiler checks them, and what ships is ordinary JavaScript with the types erased.
Overview
It is now the default for new JavaScript projects of any size, and most well-used libraries ship their own types. That makes it less a choice than a thing to be fluent in, which is why this course starts with what the type system is for rather than with a list of syntax.
Introduction
You should be comfortable with JavaScript before starting: TypeScript adds a type system to a language this course assumes you can already write. If you have used TypeScript only as JavaScript with annotations, Level 1 will be quick and Level 3 is where the course begins to tell you things you cannot get from the autocomplete.
Three lessons and a Level Check quiz per level, with an Expert Exam at the end. Every example is checked by the real compiler rather than stripped of its types, so breaking one on purpose shows you the actual error, with its code and its line number, before the code runs - which is the only way to learn what the compiler is telling you.
Every example is checked by the real compiler, not stripped. Break a type on purpose and the error appears with its code and line number before the code runs - which is the only way to learn what the compiler is actually telling you.
By the end you will be able to type a real codebase rather than annotate it: narrow a union so the compiler proves which branch you are in, write a generic that stays readable, derive one type from another instead of maintaining both, and write the declaration file that makes an untyped dependency usable.
What you will be able to do
- Annotate only what needs annotating, and let inference do the rest
- Model a domain with unions the compiler can narrow
- Read a compiler error and know which part of it matters
- Write a generic that keeps type information instead of losing it
- Use the utility types, and build one of your own
- Type a third-party library that ships no types
What each level covers
4 levels · 16 lessons
-
Level 1 - Basic
What the type system is for, and what it costs. The first lesson is honest about the trade - what you get, and the build step and the annotations you pay for it with. Then the types you will write every day, and finally inference, which is the reason you write far fewer annotations than you expect, once you know where the compiler can work it out for itself.
4 lessons 36 min of reading
Start with Why Types, and What They Cost → -
Level 2 - Intermediate
The shapes real code needs. Interfaces and type aliases, and the question of which to use; unions with the narrowing that proves which case you are in, which is where TypeScript starts catching bugs rather than describing code; and your first generics, written as something readable rather than a wall of single letters.
4 lessons 43 min of reading
Start with Interfaces and Type Aliases → -
Level 3 - Advanced
Describing types in terms of other types. The utility types first, as the tools you reach for; then keyof, typeof and indexed access, which are what those tools are built from, so a type can be derived from a value rather than kept in step with it by hand; and finally typing functions precisely, including overloads and this.
4 lessons 46 min of reading
Start with The Utility Types → -
Level 4 - Expert
The type level as a language of its own. Conditional types and mapped types let a type be computed from another; template literal types do the same to strings, which is how a library types event names it has never seen; and declaration files plus compiler configuration are how all of it meets code you did not write.
4 lessons 54 min of reading
Start with Conditional and Mapped Types →
Guides and articles
Longer reading about this subject, written alongside the course.
Before you start
- Comfortable with JavaScript: functions, objects and arrays
- The JavaScript course, or equivalent experience
Common questions
- What does the TypeScript: From Basics to Expert course cover?
- It is 4 levels and 16 lessons: Level 1 - Basic; Level 2 - Intermediate; Level 3 - Advanced; Level 4 - Expert. Each level ends with a quiz, and the last one is an exam over the whole course.
- How long does it take?
- About 179 minutes of reading and exercises - roughly 3 hours. It is self-paced with no cohort and no start date, so you can leave and come back and the site remembers where you were.
- What do I need to know first?
- Comfortable with JavaScript: functions, objects and arrays. The JavaScript course, or equivalent experience.
- Is it free?
- Yes. Every lesson, example and quiz in this course is free to read, and you do not need an account to read them. Signing in only adds progress tracking and quiz results.
- What will I be able to do afterwards?
- Annotate only what needs annotating, and let inference do the rest. Model a domain with unions the compiler can narrow. Read a compiler error and know which part of it matters. Write a generic that keeps type information instead of losing it. Use the utility types, and build one of your own. Type a third-party library that ships no types.