TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

Fix description of Exclude and Extract types

Open jennings opened this issue 5 years ago • 0 comments

The previous description was:

Constructs a type by excluding/extracting from T all properties that are assignable to U.

This sounds to me like Exclude and Extract would do this:

interface Person {
  id: number;
  name: string;
}

type NumbersOnly = Extract<Person, number>;  // { id: number }
type NoNumbers = Exclude<Person, number>;    // { name: string }

I think "Constructs a type by excluding/extracting from T all types that are assignable to U," more clearly describes removing types from the union, rather than affecting its properties.

jennings avatar Mar 10 '20 22:03 jennings