We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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).
B::checkValue(T2)
A::checkValue(T1)
T2
T1
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.
The text was updated successfully, but these errors were encountered:
Please see https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-function-parameters-bivariant for relevant details.
Sorry, something went wrong.
No branches or pull requests
Consider this example:
B::checkValue(T2)
can overrideA::checkValue(T1)
becauseT2
is assignable toT1
(as it is its subclass).However, following code, while perfectly valid, will break the second assertion:
The text was updated successfully, but these errors were encountered: