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.
Omit removes the author field, leaving only isbn and title.Multiple fields
π€ 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.
'author' | 'title' allows omitting two different fields from the interface.Using with generics
π€ 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.