Gabriel Vergnaud
banner
gabrielvergnaud.com
Gabriel Vergnaud
@gabrielvergnaud.com
TypeScript nerd • Open Source (TS-Pattern, HOTScript) • Teacher • Staff Eng @datadog

Unleash TypeScript's full potential 👉 http://type-level-typescript.com
Love it! These sound effects are just perfect ❤️
February 25, 2025 at 1:41 AM
And here is a TypeScript Playground with the full code snippet
👇

www.typescriptlang.org/play/#code/F...
TS Playground - An online editor for exploring TypeScript and JavaScript
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
www.typescriptlang.org
February 23, 2025 at 4:26 PM
I also have a full chapter about advance uses for Mapped Types in my TypeScript course, check it out: type-level-typescript.com/mapped-types
Loops with Mapped Types — Type-Level TypeScript
Most TypeScript code is about transforming objects, so we often end up with many object variants in our codebases. Let’s learn how to generate object types by looping through the keys and values of ex...
type-level-typescript.com
February 23, 2025 at 4:26 PM
Mapped Types are a super powerful feature that you can learn about in TypeScript docs: www.typescriptlang.org/docs/handboo...
Documentation - Mapped Types
Generating types by re-using an existing type.
www.typescriptlang.org
February 23, 2025 at 4:26 PM
You need to understand how unions distribute over conditional types to fully get why `Extract` works. Its definition can be somewhat cryptic:
February 22, 2025 at 8:44 PM
yea ultimately unions and catalogs encode the same information so either option works!

To extract a member of a discriminated union, I find that using the builtin Extract utility is the simplest, but I've noticed that the way Extract works isn't immediately intuitive to most people
February 22, 2025 at 8:44 PM
I started using this pattern in one of my codebases a year ago and never looked back.

If you are also a heavy user of unions of objects, give it a try!
February 22, 2025 at 5:03 PM
And lastly, it makes writing generic function types so much easier!

No need for pesky `Extract`s or `Exclude`s 🔥
February 22, 2025 at 5:03 PM
Secondly, you can generate sub-unions super easily:
February 22, 2025 at 5:03 PM
Firstly, having a catalog greatly decreases the number of type imports you need to make:
February 22, 2025 at 5:03 PM
Thanks @ayc0.github.io! ❤️🙌
November 6, 2024 at 8:57 PM