Closed
Description
TypeScript Version: 2.7.0-rc
Search Terms: class override method parameters covariance contravaraiance variance
Code
class Example {
foo(maybe: number | undefined) { }
str(str: string) { }
compare(ex: Example) { }
}
class Override extends Example {
foo(maybe: number) { } // Bad: should have error.
str(str: 'override') { } // Bad: should have error.
compare(ex: Override) { } // Bad: should have error.
}
const ex: Example = new Override();
ex.foo(undefined);
ex.str('anything');
ex.compare(new Example());
Expected behavior:
Definition of each overridden method should have an error. Parameter is contravariant instead of covariant.
Actual behavior:
No errors at compile time. Even with strictFunctionTypes
enabled.
Playground Link:
Related Issues: