mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
34 lines
1.2 KiB
Plaintext
34 lines
1.2 KiB
Plaintext
derivedClassTransitivity.ts(18,1): error TS2322: Type 'E' is not assignable to type 'C'.
|
|
Types of property 'foo' are incompatible.
|
|
Type '(x?: string | undefined) => void' is not assignable to type '(x: number) => void'.
|
|
Types of parameters 'x' and 'x' are incompatible.
|
|
Type 'number' is not assignable to type 'string'.
|
|
|
|
|
|
==== 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
|
|
}
|
|
|
|
declare var c: C;
|
|
declare var d: D;
|
|
declare 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?: string | undefined) => void' is not assignable to type '(x: number) => void'.
|
|
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
|
|
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
|
var r = c.foo(1);
|
|
var r2 = e.foo(''); |