Learn how to unleash the full potential of the Turing Complete type system of TypeScript!
Introduction
Type-level TypeScript is an online course to take your TypeScript skills from intermediate to advanced. It will give you a solid understanding of the type system's fundamentals and guide you through its most advanced features. You will find everything you need to become a TypeScript Expert β not only in-depth content, but also fun challenges to practice your new skills, like this one right here.
Let's see if you can solve it!
Congratulation! π
Over the years, the type system of TypeScript has grown from basic type annotations to a large and complex programming language.
If you have ever looked into the code of an open-source library you may have found types that looked intimidating and foreign, like some esoteric language coming from another planet. Library code often needs to be much more abstract than the code we are used to writing; that's why it makes extensive usage of advanced TypeScript features such as Generics, Conditional Types, Mapped Types or even Recursive Types.
I mastered these concepts while working on TS-Pattern, a widely-used open-source library that has the particularity of being extremely hard to type. In this course, I hope to share what I've learned by reading too much source code and tinkering for hundreds of hours with the type system.
Types are awesome.Not only can good types catch your mistakes and typos, but they also make you more proficient by documenting your code and providing you with smart suggestions. The more your types know about your code, the better they are at helping you!
Once you're fluent in the language of types, everything becomes possible. You will be able to quickly build the abstractions you need, and stop feeling like the type system is getting in your way.
Wish you had a type-safe navigate
function that'd make sure your route parameters are correct?
Here you go π
This isn't magic. The type system is just a real programming language!
To get better at this, you first need to acknowledge that TypeScript's type system is a full-fledged programming language in itself! It's more than worth learning its fundamentals, just like you would with any other new programming language.
Throughout this course, I'll try to show the correspondence between programming concepts you already know like code branching, variable assignment, loops and data structures, and their type-level equivalent.
By assembling these building blocks, you will be able to create powerful type-level algorithms that make sure the abstractions you create are always used properly in your entire codebase.
Let's take your TypeScript skills to the next level!
1
Types & ValuesFree
Free
How can we cross the bridge between types and values? Letβs better understand type inference.
π Generic functions
π Using type parameters
π Type-level functions
2
Types are just dataFree
Free
It turns out types arenβt so different from regular javascript values. Letβs explore their similarities and differences.
π Primitive & Literal types
π unknown
& never
π The dreaded any
3
Objects & RecordsFree
Free
Objects are the most common form of data in JavaScript. Letβs learn how to create and transform object types.
π Objects vs Records
π Transforming & Merging Objects
π Open vs closed objects
π The amazing keyof
keyword
4
Arrays & TuplesFree
Free
Letβs take a look at the real arrays of the type level language: Tuples!
π Tuples vs Arrays
π Transforming Arrays & Tuples
π The power of Variadic Tuples
5
Conditional Types
The journey on the road of type-level programming begins! Let's create our first type-level algorithms using conditional types for code branching.
π The extends
keyword
π The infer
keyword
π Type constraints and as const
6
Loops with Recursive Types
Computer are great at repetitive tasks. There is no reason we shouldnβt take advantage of this for types too! Letβs learn how to loop through types using recursion and build powerful type-level algorithms.
π Imperative vs Recursive loops
π Looping through Tuples
π Type-level Map
, Filter
and Reduce
functions
7
Template Literal Types
Did you know TypeScriptβs type system can parse strings? Letβs learn how to use this power to write type-safe Domain Specific Languages.
π Generating unions of strings
π Parsing strings with recursion!
π Our first type-safe DSL
8
The Union Type Multiverse
Union types are the immensely useful, and yet one of the hardest part of the language to wrap your head around. Letβs work on our mental model of union types to truly understand what they are and predict how they will behave.
π The nature of union types
π Transforming & filtering unions
π Type narrowing
9
Loops with Mapped Types
Most of JS code is about transforming objects, resulting in lots of object variants in our codebases. Letβs learn how to dynamically generate object types by looping through the keys and values of existing ones.
π Looping through keys
π Transforming unions into objects
π ?:
and other property modifiers
π Object Index Signatures
10
Assignability Quiz
Type Assignability is at the core of TypeScript. Letβs explore how assignability works the best way I know: by playing a game!
π readonly
types
π Assignability of functions
π Type variance
π Assignability pitfalls
11
Designing Type-Safe APIs
So much of programming is about using the code of other people. Learn how the best Open Source TypeScript libraries design delightful interfaces.
π Custom error messages
π Custom autocomplete suggestions
π The Type Builder pattern
12
Conclusion
Letβs reflect on what youβve learned, and what to do next to get the most out of your new shiny TypeScript skills!
π Solving real-world problems
π Mentoring
π Contributing to libraries
Finally, we will discuss the tradeoffs of moving more of your code complexity to the type level. We will talk about compile time performance, type errors, type-level debugging and other challenges of type-level programming. It will help you reflect and take the right decision when using these techniques.
This course isn't a collection of TypeScript tricks! I believe that building a good mental model of the fundamentals is more empowering because it will help you solve problems we haven't covered. Knowing a few tricks can only get you so far, but mastering the building blocks of the language and the way they interact together will enable you to solve your real-world problems.
Let's get started!
Enroll in Type-Level TypeScript!
Get access to all chapters of the Type-Level TypeScript course and join a community of 1600+ students!
You will find everything you need to become a TypeScript Expert β 11 chapters of in-depth, unique content, and more than 70 fun challenges to practice your new skills.
Full access to all 11 chapters
70 type challenges with explanations
Lifetime access to all course materials
Exclusive discord community
Loading...