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

Fix typo

Open vwkd opened this issue 5 years ago • 0 comments

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.

vwkd avatar Apr 04 '20 09:04 vwkd