Omit

This lesson explains the omit mapped type.

The mapped type Omit is the inverse of Pick. While Pick is used to select a member of a type, Omit takes everything except the member selected. Before going any further, here is the exact same example from Pick, except using the Omit mapping instead.

In the following code, lines 1 to 10 define a type with an interface called Animal. However, in lines 17 to 21, we have a function that requires a subset of all the fields of an animal. We could Pick the field needed, however in the scenario where only a few fields need to be removed, Omit is preferred. The reason is that fewer fields need to be specified: only the one not desired. Line 13 has a function that removes three fields from Animal.

Get hands-on with 1400+ tech skills courses.