TypeScript's Omit, explained
It will remove fields from a given object type. It's useful in making subsets of an object type.
The TypeScript helper called
Omit is really useful! It will remove fields from a given object type. It’s useful in making subsets of an object type.
🤔 What if we want to omit more fields? —
Omit can take away more fields by joining many fields with a union type. Here it is removing two fields.
🤔 What if we want to reuse
Omit on many things, not just books? — We can use a generic type that we can reuse on types other than
Book. How about with a
Tweet, for example:
Pick: the opposite of Omit
The opposite of Omit is
Pick, which removes all fields except the ones you want.
Thanks for reading! I'm Rico Sta Cruz, I write about web development and more. Subscribe to my newsletter!