27 lines
No EOL
879 B
Text
27 lines
No EOL
879 B
Text
==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassTransitivity.ts (1 errors) ====
|
|
// subclassing is not transitive when you can remove required parameters and add optional parameters
|
|
|
|
class C {
|
|
foo(x: number) { }
|
|
}
|
|
|
|
class D extends C {
|
|
foo() { } // ok to drop parameters
|
|
}
|
|
|
|
class E extends D {
|
|
foo(x?: string) { } // ok to add optional parameters
|
|
}
|
|
|
|
var c: C;
|
|
var d: D;
|
|
var e: E;
|
|
c = e;
|
|
~
|
|
!!! Type 'E' is not assignable to type 'C':
|
|
!!! Types of property 'foo' are incompatible:
|
|
!!! Type '(x?: string) => void' is not assignable to type '(x: number) => void':
|
|
!!! Types of parameters 'x' and 'x' are incompatible:
|
|
!!! Type 'string' is not assignable to type 'number'.
|
|
var r = c.foo(1);
|
|
var r2 = e.foo(''); |