File: derivedGenericClassWithAny.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (62 lines) | stat: -rw-r--r-- 2,604 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,18): error TS2322: Type 'string' is not assignable to type 'T'.
  'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,9): error TS2322: Type 'string' is not assignable to type 'T'.
  'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(41,1): error TS2322: Type 'E<string>' is not assignable to type 'C<number>'.
  Types of property 'x' are incompatible.
    Type 'string' is not assignable to type 'number'.


==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts (3 errors) ====
    class C<T extends number> {
        x: T;
        get X(): T { return null; }
        foo(): T {
            return null;
        }
    }
    
    class D extends C<number> {
        x: any;
        get X(): any {
            return null;
        }
        foo(): any {
            return 1;
        }
    
        static y: any;
        static get Y(): any {
            return null;
        }
        static bar(): any {
            return null;
        }
    }
    
    // if D is a valid class definition than E is now not safe tranisitively through C
    class E<T extends string> extends D {
        x: T;
        get X(): T { return ''; } // error
                     ~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'T'.
!!! error TS2322:   'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
        foo(): T {
            return ''; // error
            ~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'T'.
!!! error TS2322:   'string' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'string'.
        }
    }
    
    var c: C<number>;
    var d: D;
    var e: E<string>;
    
    c = d;
    c = e;
    ~
!!! error TS2322: Type 'E<string>' is not assignable to type 'C<number>'.
!!! error TS2322:   Types of property 'x' are incompatible.
!!! error TS2322:     Type 'string' is not assignable to type 'number'.
    var r = c.foo(); // e.foo would return string