I would expect the following code to fail to transpile, as B should not be a valid type for array.push. What am I missing?
class A {};
class B {};
const arr: A[] = [];
arr.push(new B());
I would expect the following code to fail to transpile, as B should not be a valid type for array.push. What am I missing?
class A {};
class B {};
const arr: A[] = [];
arr.push(new B());
TypeScript uses structural compatibility to determine type compatibility. The classes are structurally compatible since they have the same properties (empty object).
See: https://www.typescriptlang.org/docs/handbook/type-compatibility.html