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