正在加载视频...

视频加载失败

🔥 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 次观看 • 3 年前 •via X (Twitter)

10 条评论

Fernando Rojo 的头像
Fernando Rojo3 年前

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

Matt Pocock 的头像
Matt Pocock3 年前

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

Sumit | Frontend 的头像
Sumit | Frontend3 年前

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

calebcodes 的头像
calebcodes3 年前

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 的头像
Roman Holubenko3 年前

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 的头像
Jimmy Thompson3 年前

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 的头像
Uberto Barbini @ramtop.bsky.social3 年前

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

fuko 的头像
fuko3 年前

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

harpaljadeja.eth (evm/acc) 🇮🇳 的头像
harpaljadeja.eth (evm/acc) 🇮🇳3 年前

Damn your animator is already working!

Edun Omatseye 🔥 的头像
Edun Omatseye 🔥3 年前

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

相关视频