As I am working a lot with TypeScript these days I ran into some interesting TypeScript Utility types that I would like to explore a bit more in a series of small blog posts.

Pick<Type,Keys>

The Pick utility type is the opposite of Omit. With Pick we are able to define a new type by selecting one or multiple keys from an existing type.

example:

type Pizza = {
  name: string,
  spiciness: number,
  price: number
}

We can create a new type of a Pizza with the Pick utility. The result is a type with just the name of the Pizza.

type PizzaWithJustTheName = Pick<Pizza, "name">;

Creating an object of this type would look something like:

const pizza: PizzaWithJustTheName = {
  name: 'Quatro Stagioni'
}

You can also take it one step further by selecting mutiple keys:

type PizzaWithoutPrice = Pick<Pizza, "name" | "spiciness">;

For a complete overview of TypeScript Utility types please check:

TypeScript handbook utility types