Search⌘ K

Extract

Explore how to use the Extract mapped type in TypeScript to identify common members between different types. Understand how Extract enables the creation of functions that operate safely on intersecting type properties, making your code more adaptable as types evolve.

We'll cover the following...

Description of Extract

The next mapped type is Extract. It allows us to extract from a set of types the one that is common in another type. The following code shows that the first generic argument has three variables (string, string[], and number) and the second generic type is unknown[], which means any kind of array. Extract returns string[] | number[] ...