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 typo #1310

Open vwkd opened 4 years ago

vwkd commented 4 years ago

The handbook reads

x is compatible with y if y has at least the same members as x

I believe the types should be flipped

y is compatible with x if y has at least the same members as x

Because compatibility is viewed from the point of view of the type that is assigned not from the point of view of the type being assigned to.

An example:

interface Named {
  name: string;
}

class Person {
  name: string;
  age: number;
}

let x: Named;
let y = new Person();

x = y; // valid, since y is compatible with x
y = x; // invalid, since x is not compatible with y

Mathematically speaking, y is compatible with x iff x \subseteq y, instead of y \subseteq x like currently stated.