-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Description
Consider this example:
class T1 {
prop1: string = 'T1/prop1';
}
class T2 extends T1 {
prop2: string = 'T2/prop2';
}
class A {
propA: string;
checkValue(value: T1) {
console.assert(!!value.prop1);
}
}
class B extends A {
propB: string;
checkValue(value: T2) {
console.assert(!!value.prop2);
}
}B::checkValue(T2) can override A::checkValue(T1) because T2 is assignable to T1 (as it is its subclass).
However, following code, while perfectly valid, will break the second assertion:
const a: A = new B();
const t1: T1 = new T1();
a.checkValue(t1); // B.prototype.checkValue(), expecting T2 but getting T1.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead