File: derivedClassTransitivity3.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (34 lines) | stat: -rw-r--r-- 1,487 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassTransitivity3.ts(18,1): error TS2322: Type 'E<string>' is not assignable to type 'C<string>'.
  Types of property 'foo' are incompatible.
    Type '(x: string, y?: number) => void' is not assignable to type '(x: string, y: string) => void'.
      Types of parameters 'y' and 'y' are incompatible.
        Type 'string' is not assignable to type 'number'.


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