Loading video...

Video Failed to Load

Go Home

🔥 TypeScript Tip 🔥 Omit and Pick are the gateway to understanding type-level programming. They let you start deriving types, instead of redeclaring them.

232,311 views • 3 years ago •via X (Twitter)

10 Comments

Fernando Rojo's profile picture
Fernando Rojo3 years ago

i like combining them to add type suggestions to Omit itself: type Omitted = keyof Pick<User, ‘role’> type WithoutRole = Omit<User, Omitted>

Matt Pocock's profile picture
Matt Pocock3 years ago

Or type StrictOmit<T, K extends keyof T> = Omit<T, K>;

Sumit | Frontend's profile picture
Sumit | Frontend3 years ago

Which tool do you use to edit these videos? 🥺🥺🥺 please Matt

calebcodes's profile picture
calebcodes3 years ago

Very interesting. Any reason to prefer one of these over "traditional" inheritance (extending interfaces to add fields)? I can see how there are some semantic benefits to Pick/Omit, but I wonder if they'd lead to some bad practices from an OOP perspective 🤔

Roman Holubenko's profile picture
Roman Holubenko3 years ago

Very useful, but now I have a question: what better way to structure types on the project would you suggest? Making a single file named "types" and export all needed types from there, or writing types inside working files where you use them?

Jimmy Thompson's profile picture
Jimmy Thompson3 years ago

Definitely a powerful tool, but should be used with care IMO. These patterns crept into our codebase and caused an explosion in types, each used only once. As much as types are for type safety, they're to help you describe your domain. Meaningless types are as bad as no types.

Uberto Barbini @ramtop.bsky.social's profile picture
Uberto Barbini @ramtop.bsky.social3 years ago

I wish we could do something like this in kotlin... :(

fuko's profile picture
fuko3 years ago

short and sweet! I particularly love this format, thanks for the vid! 😊

harpaljadeja.eth (evm/acc) 🇮🇳's profile picture
harpaljadeja.eth (evm/acc) 🇮🇳3 years ago

Damn your animator is already working!

Edun Omatseye 🔥's profile picture
Edun Omatseye 🔥3 years ago

just only natural to do a follow up video on Extract<> and Exclude<> 🤞

Related Videos