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 , instead of like currently stated.
The handbook reads
I believe the types should be flipped
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:
Mathematically speaking,
, instead of
like currently stated.
y
is compatible withx
iff