TypeScript Gymnastics: Why Are They So Powerful for You?

This ad is not shown to multipass and full ticket holders
React Summit US
React Summit US 2025
November 18 - 21, 2025
New York, US & Online
The biggest React conference in the US
Learn More
In partnership with Focus Reactive
Upcoming event
React Summit US 2025
React Summit US 2025
November 18 - 21, 2025. New York, US & Online
Learn more
Bookmark
Rate this content

In TypeScript’s type system is more than just a tool for catching errors—it’s a way to solve complex problems with clean and reliable code. In this talk, we’ll dive into advanced TypeScript techniques like mapped types, conditional types, and generics to handle even the trickiest type challenges.

You’ll see how these techniques can help you extract, transform, and validate data types while keeping your code simple and maintainable. These "TypeScript gymnastics" aren’t just for show—they’re practical skills that make your systems stronger and easier to work with.

Come learn how to take full advantage of TypeScript’s flexibility and power to build solutions that are as smart as they are safe.

This talk has been presented at JSNation 2025, check out the latest edition of this JavaScript Conference.

FAQ

The talk focuses on advanced features of TypeScript, explaining how to improve code stickiness and make TypeScript code more strict.

Understanding where JavaScript ends and TypeScript begins is crucial for working with advanced TypeScript features and ensuring proper integration of both languages in your codebase.

Template literal types in TypeScript are used to create new types from existing ones by combining them in specific formats, such as creating runner statuses by combining runner names with states.

Some built-in TypeScript utilities mentioned include 'ReturnType', 'Partial', 'Required', 'Readonly', 'Extract', 'Exclude', 'Pick', and 'Omit', which help in manipulating and extracting type information.

Luca advises not to forget to create tests for your codebase, as tests serve a different purpose than types, and highlights the importance of balancing time investment with the benefits of using TypeScript.

The speaker is Luca Del Pupo, an Estonian Software Engineer at Pneumformal, specializing in JavaScript and TypeScript.

Using TypeScript can significantly improve developer experience by reducing errors, guiding feature creation, and providing a more structured approach to code development.

Challenges include the need for extensive knowledge, time to implement, and potential headaches when understanding complex TypeScript functionalities.

TypeScript allows you to define specific literal types for state management, ensuring that state values are restricted to specified options like 'starting', 'running', 'arriving', or 'retiring'.

TypeScript uses conditional types with a pattern matching approach, utilizing the 'extends' keyword to determine if certain conditions are met and then returning specific types based on these conditions.

Luca Del Puppo
Luca Del Puppo
23 min
16 Jun, 2025

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The Talk delves into TypeScript, highlighting its introduction, differences from JavaScript, and providing code examples. It emphasizes the significance of strict typing in TypeScript, showcasing the use of literal types and union types for precise type modeling. The discussion also covers template literal types for creating combined types and precise type matching, as well as conditional handling without if statements and function type inference. Furthermore, it explores looping, recursion, object type manipulation, key manipulation, mapper type, and TypeScript utility types for efficient property management and type manipulation.

1. TypeScript Introduction and Code Examples

Short description:

Introduction to TypeScript, understanding JavaScript and TypeScript differences, and code examples.

Hello and welcome to this talk where I talk about TypeScript and some advanced features of it. First of all, who I am. I'm Luca Del Pupo, Estonian Software Engineer at Pneumformal of JavaScript and TypeScript. And in my free time I try to run my YouTube channel, but I'm failing in that period because of time. And I also write the tech posts for tech people. In my free time, I also run, love running, hiking, and I love animals. By the way, let's start from here.

Probably most of you already came across something like this, a TypeScript file definition with thousands and thousands of rows and very difficult to understand. So today I'll try to help you to understand what happened inside of this file and how you can create your TypeScript function to improve the stickiness of your code base and to make your TypeScript code more strict. So at this point, let's jump to the code. Let's start from here. When you work with TypeScript and JavaScript, you have to understand where JavaScript and when TypeScript start.

For instance, in this example, we have a mix of, for instance, we have a type welcome and a const welcome, both with the same name. As you can see here, types is a specific type welcome with the value welcome to everybody. And const is a JavaScript variable in this case, with a string value welcome to everybody. This part is just TypeScript. This part is a mix of JavaScript and TypeScript. This code is real JavaScript code and this code will run after in your browser or inside of, I don't know, your node server or something. And this part, the second part of this line is only TypeScript code.

2. TypeScript Type Modeling and Union Types

Short description:

Understanding the importance of strict typing in TypeScript and using literal types and union types for precise type modeling and checking.

This helps us to make welcome to everybody const and we check if this string meets the welcome type. If you understand when JavaScript and TypeScript start, then you can start to work with advanced TypeScript. Today, I show you only code of TypeScript that basically disappears after the build phase, but help you to increase the developer experience or increase the stickiness of your app. Let's start from here.

When you work with TypeScript, it's important to be strict when you model your types. For instance, in this case, if you have a state, state can be a string. A string is too much open as value for what we want to describe. For instance, in this case, state can be starting, running, arriving, or retiring. And using TypeScript, we can do it using specific types, a literal type called starting. So, in this case, starting is not a real string, but is a type starting that say to TypeScript, the string must be a starting string, a string with a specific value starting, or a specific value running, or a specific value arriving, or a specific value retiring. And using the pipe, we can create a sort of order.

So, in this case, it can be one of these, but only once in a specific time. And then we can check if state, state in this case is equal to starting, is both a real string, but is also a string that in this case match with the state string, with the state type. Then using, we can use the pipes, so the union type also with other kind of type. For instance, the true, the false, we can create other type and we can mix true, false, and zero or one of type string and blah, blah, blah. We can use a union type also with the type, with object type.

3. Template Literal Type and Type Matching

Short description:

Exploring template literal type for creating combined types like runner status and using template syntax for precise type matching such as RGB patterns.

And as you can see here, status, status is equal to zero and match the status. If you understand how literal types works, you can move to template literal type. In some cases, we want to create types from other types, in this case from string literal type. And for instance, what we want to do is to create a sort of combination between runner and state. So runner can be Kevin, John, or Dough. And state can be starting, running, arrived, and retired. We want to create a running status that basically match the runner name, is, and the state of the runner.

In this case, using the template syntax, so the backtick, and then using the common template syntax that you probably use in JavaScript, you can basically mix together the types and create the runner status. In this case, as you can see, runner status is a combination of all the possible runners with all the possible states, using the is. And if, for instance, remove the state, out of the box TypeScript removes this computation for us. And this means that if someone adds a new state, we will have for free the new status already mapped inside of the runner state.

And as you can see here, we can create a string that must match the specific types. In this case, arrived is without e at the end. And as you see, TypeScript is able to understand that Kevin is arrived without e, is not assignable to a runner state. Then we can use template syntax also to create other kinds of types. For instance, in this case, using RGB, we can say the first part here must be a number. Then there is a comma, another number, and another comma. In this way, we can describe the RGB pattern of a column. And as you can see here, we can use RGB, and in this case, 230, zero, and blah, blah, blah.

4. Conditional Handling and Function Type Inference

Short description:

Exploring RGB usage and strict typing with template syntax, understanding conditional handling without if statements, and leveraging the return type condition for function type inference.

And as you can see here, we can use RGB, and in this case, 230, zero, and blah, blah, blah. But if I set a as the second value for the green part, as you can see, TypeScript is able to understand that a cannot be assignable to a number. This means that your thing cannot be assignable to an RGB color type. And as you can imagine, using this template syntax, we can create many, many types that help us to be more strict with our type system and to modeling in the best way the shape of our object and our types.

So when you understand this one, it's time to understand how we can handle if and else using the type system. Unfortunately, the type system doesn't have a real if statement but uses a sort of pattern matching. Take a look at this if condition type. This is a condition type, except three generic types. The first one is a condition, the second one is the true value if the condition is met, and the third one is the else if the condition doesn't. What does it mean? The first part is a condition that can be true or false.

And here, what we are doing is if C extends true, return the T generics; otherwise, return else. How we can use it? As you can see here, if I pass true and yes or no, the if will return yes. If I pass false, yes or no, the if will return no. This means that using the extends, we can create a sort of if, and if the extends have been met, we can do something. Otherwise, we can do other. So if you understood how the condition and the extend keyword works, you can move to the next example, the return type condition.

5. Return Type Condition and Parameter Handling

Short description:

Understanding return type condition for function type inference, using parameters, and extracting data from specific literal types like RGB in TypeScript.

What this condition does is this return type condition accepts a generic T, and this T is a generics, and we want to check if the T is a kind of function, and if this is a function, please infer the return type of the function inside of R. If T basically is a function, at the end, we will return the return type of this function. Otherwise, we will return what is never. Never is nothing. This means that it is something that doesn't have nothing inside. In this case, the return condition, if I pass a function that returns a string, return a string. If I pass a function that returns a Boolean, return a Boolean. If I pass a Boolean, for instance, return a never. And the return type condition is already built in TypeScript. It's called a return type, and you can already use it to extract the return type of a function. And this means that you can extract the type from the function, and you don't have to recreate again the type. It means you have this type from an external library. You don't want to recreate the types, but you want to depend on that type. Using the return type, you can extract it from this function, and create, and then use this type for your business. The same we can do for the parameters.

So in this case, instead of using the infer inside of the return, we can use it inside of the parameter. The args is an array, so P at the end will be an array with all the parameters inside of it. In this case, the first one is without parameters, so there is an empty array. In this case, there are just one parameter with number, and we have an array with only one element, number. And also for the parameter condition, we already have a parameter built in inside of TypeScript, and the function is called parameter. You can use the extend also to extract data from a specific literal type. For instance, in this case, as you can see, we have an RGB type. And we want to check if the T is an RGB type, and we want to extract the red, the green, and the blue. Using T, we can do extend, we can use the backtick RGB, then we want to infer R, and if we want R be a number, the same we want to do with G, and we want that G is a number, and B blah, blah, blah. At the end, we want to return RGB if T extends the RGB number. Otherwise, we will return never. As you can see here, we can extract 255 for RGB here. We can extract the red, green, and blue also here. It's important to pay attention of this space, because if I remove the space from here, as you can see, this doesn't meet the requirement, because this one doesn't meet the pattern inside of the extend. As you can see, you have to pay attention also on these smaller things, because sometimes these can create a wrong result.

6. Looping and Object Type Manipulation

Short description:

Understanding looping and recursion in TypeScript to extract data, creating different types of loops, working with object types, and manipulating them by adding, removing, and modifying fields.

Okay, now it's time to move to loop. Okay, we understood how we can create if, and else. Now, it's time to understand how we can loop types to extract data. In each, you have a type, a user type that is an array that contain for each element of the array the column definition. In this case, name, first name, and value, name, last name, the value are string, and name, role can be manager or employee. We want to create a sort of get column that can be used in this way. We want to pass a user table and the name of the value, and return the definition of that column if exists. How we can do that? Using the loop. Unfortunately, in TypeScript, we cannot loop, but we can use recursion. So, how we can do that? Using list. We can check if list extend an array, and we want to pick the first element of the array, and basically spread the rest of the array inside of the rest. First, now we have to check if first extend a column with our specific name. If so, we can return first, otherwise, we want to iterate the list, the rest of the list.

How we can do that? We can call again, get column. But this time, we don't pass a list, but we pass the rest of the column that we haven't checked yet with the same name. This, as you can imagine, is a sort of recursion that, at some point, this list, if you don't have any column with that name, you will return never. Otherwise, at some point, you will return the first, and this is the result. You can basically create also other kind of loop, more simpler. For instance, in this case, we can use append. You have a tuple and the element using the spread. Basically, you can create another type with the first part of the array and the new element. In this case, we have one, two, three, and four, and the result is one, two, three, four. If you have an empty array, you can pass four. If you have a lot, you can have a lot and a lot, and blah, blah. You can also mix. You can create, find, filter, whatever you want. This is just a matter of what you need to do, and you can create your own TypeScript conditional type to create other types.

Another important part, when we work with TypeScript, we want to work with object types, and we want to manipulate them. What we want to do is to remove a field, add a field, or remove optional condition, or make everything optional, or add read-only, and blah, blah. To do that, we must know just two important things in TypeScript, the key of a keyword and the mapper type.

7. Key Manipulation and Mapper Type in TypeScript

Short description:

Exploring the key of and mapper type in TypeScript to manipulate object types and create new objects based on existing types.

The key of is a specific keyword that allows us to get all the props of a specific type. In this case, if I call key of person, I will receive all the first-level props of the person interface. In this case, name, so name, age, gender, address, email, phone, and policy accepted.

Then we have the mapper type. Mapper type is the way to manipulate the types of object inside of TypeScript. The syntax is pretty simple. It's like the object syntax, and we have to define the key of the object and the type of that key.

Using key in, we are saying, okay, for each k inside of this list of key, in this case, all the person key, basically, you are creating a new object. In this way, I basically recreate the same person type using the mapper type.

8. TypeScript Utility Types and Manipulation

Short description:

Exploring key manipulation with the mapper type in TypeScript to recreate interfaces, manipulate data, create optional properties, and manage required properties efficiently.

What I want to do is basically use the key of, so I want to iterate to all the key of the person, and using the person bracket key, I can square bracket key, I can get the type of this specific key. The result is this new person that basically is the same interface recreated using the mapper type. If you understand how mapper types work, you can manipulate also the data.

For instance, you want to make everything optional. In this case, we want to create a partial person. Using the same syntax, you can add the question mark, in this case, and this means that for the partial person, we have all the question mark inside of the properties. This work only in the first level. If you want to do it also deep inside of each element, you have to create another type here.

If the person key type is an object, you have to iterate inside of the types and create this also inside of the nested object. Then, partial utility is already built in in TypeScript, so you can use partial person here. You can use required and the same is here. The required remove the question mark, so you will just need to add the dash before the question mark, and the result is basically you have all required, and required here is, as you can see, already implement.

9. TypeScript Property Management and Utility Types

Short description:

Exploring read-only, extract, pick, omit, and utility types in TypeScript for managing properties efficiently and creating types that depend on others.

Or you can create the read-only utility type. Basically, you want to add the read-only keyword for each property in this case, and also read-only is already built in if you want. And you can also use extract. Extract allow you to extract type from a specific type. For instance, in this case, you have extract type name, or surname or age, and you want to extract name and surname. Using the extract type, you have name and surname.

Extract is already built in in TypeScript, or you can use exclude that is the opposite of extract, or, for instance, you want to use pick or omit. Pick is basically a way to, from a type, pick only specific properties, like in this way, and pick is already implement. Also, in TypeScript, omit is the opposite. If you want to remove properties from a specific type, you have to basically use a pick and exclude all the properties that you want to exclude from. Pretty simple.

Using all this kind of utility, you can create and manipulate your types and create types that depend on other types. At the end, what happens is that you can have something like this. You can create a sort of get key function that accepts an object key and a key key that this key is a property that matches the specific property name that exists inside of T. This get all key utility is a bit enigmatic, but you can check it out in the repo without any problem. That basically uses all these kind of things that we've seen before to build a sort of union literal type with all the possible properties inside of that type.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
TypeScript and React: Secrets of a Happy Marriage
React Advanced 2022React Advanced 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
Making Magic: Building a TypeScript-First Framework
TypeScript Congress 2023TypeScript Congress 2023
31 min
Making Magic: Building a TypeScript-First Framework
Top Content
Daniel Rowe discusses building a TypeScript-first framework at TypeScript Congress and shares his involvement in various projects. Nuxt is a progressive framework built on Vue.js, aiming to reduce friction and distraction for developers. It leverages TypeScript for inference and aims to be the source of truth for projects. Nuxt provides type safety and extensibility through integration with TypeScript. Migrating to TypeScript offers long-term maintenance benefits and can uncover hidden bugs. Nuxt focuses on improving existing tools and finds inspiration in frameworks like TRPC.
Stop Writing Your Routes
Vue.js London 2023Vue.js London 2023
30 min
Stop Writing Your Routes
Top Content
Designing APIs is a challenge, and it's important to consider the language used and different versions of the API. API ergonomics focus on ease of use and trade-offs. Routing is a misunderstood aspect of API design, and file-based routing can simplify it. Unplugging View Router provides typed routes and eliminates the need to pass routes when creating the router. Data loading and handling can be improved with data loaders and predictable routes. Handling protected routes and index and ID files are also discussed.
The State of the Web
JSNation 2025JSNation 2025
32 min
The State of the Web
Sasha Grief discusses the state of the web through web development surveys, leading to an interactive quiz about the state of JS and usage of front end frameworks. Discussion on popular front-end libraries like React, Vue, Angular, and the rising popularity of TypeScript among developers in recent surveys. Discussion on TypeScript adoption, TC39 committee proposals, favorite CSS feature 'has,' and browser support for 'has' selector. Browser interoperability, browser vendors' initiatives, AI usage among web developers, and survey insights. Job titles linked to higher income, diversity of survey topics, top hobby among developers, and popular specific video games. Learnings on CSS features, TypeScript default, AI usage, survey benefits, challenges in reaching diverse survey participants. Surprising positivity in JavaScript usage, stable framework landscape, AI adoption challenges, mainstream AI tools, successful situp.js survey. Inconsistent respondent numbers, manual data normalization efforts, subjective question selection process, community input, mitigation of selection bias. Reason for starting surveys, transition from Meteor JS, exploration of JavaScript ecosystem.
Faster TypeScript builds with --isolatedDeclarations
TypeScript Congress 2023TypeScript Congress 2023
24 min
Faster TypeScript builds with --isolatedDeclarations
Top Content
This talk discusses the performance issues in TypeScript builds and introduces a new feature called isolated declarations. By running the compiler in parallel and using isolated modules, significant performance gains can be achieved. Isolated declarations improve build speed, compatibility with other tools, and require developers to write types in code. This feature has the potential to further increase performance and may be available in TypeScript soon.

Workshops on related topic

React, TypeScript, and TDD
React Advanced 2021React Advanced 2021
174 min
React, TypeScript, and TDD
Top Content
Featured Workshop
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced 2022React Advanced 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Practice TypeScript Techniques Building React Server Components App
TypeScript Congress 2023TypeScript Congress 2023
131 min
Practice TypeScript Techniques Building React Server Components App
Workshop
Maurice de Beijer
Maurice de Beijer
In this hands-on workshop, Maurice will personally guide you through a series of exercises designed to empower you with a deep understanding of React Server Components and the power of TypeScript. Discover how to optimize your applications, improve performance, and unlock new possibilities.
 
During the workshop, you will:
- Maximize code maintainability and scalability with advanced TypeScript practices
- Unleash the performance benefits of React Server Components, surpassing traditional approaches
- Turbocharge your TypeScript with the power of Mapped Types
- Make your TypeScript types more secure with Opaque Types
- Explore the power of Template Literal Types when using Mapped Types
 
Maurice will virtually be by your side, offering comprehensive guidance and answering your questions as you navigate each exercise. By the end of the workshop, you'll have mastered React Server Components, armed with a newfound arsenal of TypeScript knowledge to supercharge your React applications.
 
Don't miss this opportunity to elevate your React expertise to new heights. Join our workshop and unlock the potential of React Server Components with TypeScript. Your apps will thank you.
Advanced TypeScript types for fun and reliability
TypeScript Congress 2022TypeScript Congress 2022
116 min
Advanced TypeScript types for fun and reliability
Workshop
Maurice de Beijer
Maurice de Beijer
If you're looking to get the most out of TypeScript, this workshop is for you! In this interactive workshop, we will explore the use of advanced types to improve the safety and predictability of your TypeScript code. You will learn when to use types like unknown or never. We will explore the use of type predicates, guards and exhaustive checking to make your TypeScript code more reliable both at compile and run-time. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Are you familiar with the basics of TypeScript and want to dive deeper? Then please join me with your laptop in this advanced and interactive workshop to learn all these topics and more.
You can find the slides, with links, here: http://theproblemsolver.nl/docs/ts-advanced-workshop.pdf
And the repository we will be using is here: https://github.com/mauricedb/ts-advanced