microsoft / TypeScript-Handbook

Deprecated, please use the TypeScript-Website repo instead
https://github.com/microsoft/TypeScript-Website
Apache License 2.0
4.88k stars 1.13k forks source link

Fix description of Exclude and Extract types #1307

Open jennings opened 4 years ago

jennings commented 4 years ago

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.