The Type Transformations workshop is your guide to TypeScript features and patterns that allow you to manipulate types to produce exactly what you want. As you begin to see how the pieces fit together, you’ll find yourself writing less code that is easier to maintain.
There are over 50 exercises in this workshop, each with a challenge designed to help you learn to wield the power of transforming strings into objects, objects into unions, and everything in between.
I am sorry but I can not say it in different words. THIS WORKSHOP IS FU**ING AMAZING.
The TypeScript compiler uses type inference to automatically determine the data type of a value depending on the context in which it is used. We can use several utilities and operators to define our own types more precisely.
Unions & Indexing Unions
Union types play a key role in the type transformation process. In this section we will work at unions and discriminated unions, as well as how to access their properties with indexed access types. Several of TypeScript’s built-in utility types will also be explored.
As of TypeScript 4.1, template literals can be used to power amazing inference on strings. In this section we’ll practice using template literals to help create object types, split strings into tuples, and other useful transformations.
Type helpers allow you to manipulate and work with types in a more convenient way. They allow you to set constraints that ensure your types are as you expect while retaining flexibility for reuse. The type helper pattern is important to understand, as it forms the basis of many of TypeScript's core features.
Conditional Types & Infer
In this section, we will further explore how to leverage the type helpers pattern, paying special attention to conditional types and inference when working with functions, objects, and Promises.
With TypeScript's mapped types, you can transform any type into and out of objects, unions, and tuples. It's an amazingly flexible tool for creating all sorts of different types. You’ll get practice with all of these, as well as using template literals to dynamically customize your types. One learner wrote they'd been using TS for 2 years and finally understood Mapped Types after this section!
To tie up the previous exercises, we've put together several real-world challenges that will put your Type Transformation skills to the test.