Given:
class Base {}
class D1 extends Base{}
class D2 extends Base{}
const d1: D1 = new D1();
function printD2(d2: D2) {
console.log(d2)
}
printD2(d1);
I would have expected an error passing d1
into printD2
. They are structurally the same, yet they are derived types. Why is this? How to prevent this? At runtime this d1 instanceof D2
would return false
.