Pro Workshop

Type Transformations

Type Transformations

There are two full worlds in TypeScript.

The typeof operator is your wardrobe door from the Runtime World to the Type World.

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 40 lessons in this workshop, each with a challenge designed to help you learn to wield the power of transforming strings into objects, object into unions, and everything in between.

This workshop is perhaps the most abstract of the Total TypeScript series, but understanding how type transformations flow into one another is foundational to the later workshops in this series.

Inference Basics

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 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.

Template Literals

In TypeScript, template literals can contain types. This allows for more specificity when working with strings throughout our applications. In this section we’ll practice using template literals to help create object types, split strings into tuples, and other useful transformations.

Conditional Types & Infer

The Type Helper pattern is the basis of many of TypeScript's core features and is useful when you don't want to declare new type annotations or work with library code. In this section, we will explore how to use Type Helpers with functions, objects, and Promises, as well as how to best leverage the pattern when working with conditional logic.

Key Remapping

With TypeScript's mapped types, you can transform any type into and out of objects, unions, and tuples. You’ll get practice with all of these, as well as using template literals to dynamically customize your types.

Extended Challenges

Drawing on the previous sections are several real-world challenges that will put your Type Transformation skills to the test.