TypeScript-Handbook
TypeScript-Handbook copied to clipboard
Fix typo
The handbook reads
xis compatible withyifyhas at least the same members asx
I believe the types should be flipped
yis compatible withxifyhas at least the same members asx
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 , instead of
like currently stated.