Gabriel Vergnaud's Avatar

Gabriel Vergnaud

@gabrielvergnaud.com.bsky.social

TypeScript nerd β€’ Open Source (TS-Pattern, HOTScript) β€’ Teacher β€’ Staff Eng @datadog Unleash TypeScript's full potential πŸ‘‰ http://type-level-typescript.com

269 Followers  |  134 Following  |  19 Posts  |  Joined: 19.11.2023  |  1.8154

Latest posts by gabrielvergnaud.com on Bluesky

Preview
Release v5.7.0 Β· gvergnaud/ts-pattern New feature Exhaustive callback By default, .exhaustive() will throw an error if the input value wasn't handled by any .with(...) clause. This should only happen if your types are incorrect. It is ...

Release note πŸ‘‡
github.com/gvergnaud/ts...

28.03.2025 20:50 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

A new version of TS-Pattern is out 🚨

You can now customize the fallback behavior of `.exhaustive()` if the runtime value you get is unexpected.

upgrade πŸ‘‰ npm i ts-pattern@5.7.0

28.03.2025 20:50 β€” πŸ‘ 8    πŸ” 2    πŸ’¬ 3    πŸ“Œ 0

Love it! These sound effects are just perfect ❀️

25.02.2025 01:41 β€” πŸ‘ 0    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
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.

And here is a TypeScript Playground with the full code snippet
πŸ‘‡

www.typescriptlang.org/play/#code/F...

23.02.2025 16:26 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
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...

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

23.02.2025 16:26 β€” πŸ‘ 6    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Documentation - Mapped Types Generating types by re-using an existing type.

Mapped Types are a super powerful feature that you can learn about in TypeScript docs: www.typescriptlang.org/docs/handboo...

23.02.2025 16:26 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Video thumbnail

Here is another reason I like Type Catalogs.

They can easily be transformed with Mapped Types!

Full code snippet in thread πŸ§΅πŸ‘‡

23.02.2025 16:26 β€” πŸ‘ 19    πŸ” 3    πŸ’¬ 1    πŸ“Œ 0
Post image

You need to understand how unions distribute over conditional types to fully get why `Extract` works. Its definition can be somewhat cryptic:

22.02.2025 20:44 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

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

22.02.2025 20:44 β€” πŸ‘ 1    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0

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!

22.02.2025 17:02 β€” πŸ‘ 4    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

And lastly, it makes writing generic function types so much easier!

No need for pesky `Extract`s or `Exclude`s πŸ”₯

22.02.2025 17:02 β€” πŸ‘ 5    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

Secondly, you can generate sub-unions super easily:

22.02.2025 17:02 β€” πŸ‘ 3    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

Firstly, having a catalog greatly decreases the number of type imports you need to make:

22.02.2025 17:02 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 1    πŸ“Œ 0
Post image

Pro tip: Don't write your #TypeScript union types by hand, use a Type Catalog instead!

Why are Type Catalogs better?

Find out in the thread 🧡 πŸ‘‡

22.02.2025 17:02 β€” πŸ‘ 29    πŸ” 4    πŸ’¬ 2    πŸ“Œ 0
Post image

A new TS-Pattern release is out!

πŸ‘‰ Prevent passing impossible patterns to `isMatching` when used with 2 parameters.
πŸ‘‰ `P.infer` behaves better when used in an argument position.

just run `npm i ts-pattern@v5.6.0` in your project 😊

Release note: github.com/gvergnaud/ts...

15.12.2024 22:26 β€” πŸ‘ 12    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Post image

Type-Level TypeScript is on sale for Black Friday! 🚨

You can get it for 25% off! It's only 74$ to get lifetime access to all course materials.

πŸ‘‰ type-level-typescript.com

Enroll to learn how to craft and transform #TypeScript *types* with the same ease you handle JavaScript values every day!

26.11.2024 15:51 β€” πŸ‘ 12    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Video thumbnail

Template Literal Types are awesome.

If you concat `number` and a union of time units, you have a human readable AND type-safe way to provide time values! πŸ‘‡

14.11.2024 00:30 β€” πŸ‘ 14    πŸ” 3    πŸ’¬ 0    πŸ“Œ 1

Thanks @ayc0.github.io! β€οΈπŸ™Œ

06.11.2024 20:57 β€” πŸ‘ 2    πŸ” 0    πŸ’¬ 0    πŸ“Œ 0
Preview
How to get optional keys from object types in TypeScript? β€” Type-Level TypeScript Let's build a reusable type helper to get all optional keys from an object type in TypeScript.

Hey friends πŸ‘‹

Trying out @bsky.app, looks great so far!

I'll post TypeScript and programming related things.

to get started, here is an article I wrote a couple of weeks ago explaining how to get optional keys from object types πŸ€—

type-level-typescript.com/articles/how...

05.11.2024 13:44 β€” πŸ‘ 17    πŸ” 1    πŸ’¬ 1    πŸ“Œ 1

@gabrielvergnaud.com is following 20 prominent accounts