File: objectTypeWithRecursiveWrappedPropertyCheckedNominally.errors.txt

package info (click to toggle)
node-typescript 2.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 203,952 kB
  • ctags: 52,987
  • sloc: sh: 11; makefile: 5
file content (84 lines) | stat: -rw-r--r-- 3,813 bytes parent folder | download | duplicates (3)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(20,1): error TS2322: Type 'MyList<string>' is not assignable to type 'List<number>'.
  Types of property 'data' are incompatible.
    Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(22,1): error TS2322: Type 'MyList<number>' is not assignable to type 'List<string>'.
  Types of property 'data' are incompatible.
    Type 'number' is not assignable to type 'string'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(30,5): error TS2322: Type 'U' is not assignable to type 'T'.
  Type 'MyList<number>' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(31,5): error TS2322: Type 'T' is not assignable to type 'U'.
  Type 'List<number>' is not assignable to type 'U'.
tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts(42,5): error TS2322: Type 'U' is not assignable to type 'T'.
  Type 'MyList<number>' is not assignable to type 'T'.


==== tests/cases/conformance/types/typeRelationships/recursiveTypes/objectTypeWithRecursiveWrappedPropertyCheckedNominally.ts (5 errors) ====
    // Types with infinitely expanding recursive types are type checked nominally
    
    class List<T> {
        data: T;
        next: List<List<T>>;
    }
    
    class MyList<T> {
        data: T;
        next: MyList<MyList<T>>;
    }
    
    var list1 = new List<number>();
    var list2 = new List<string>();
    
    var myList1 = new MyList<number>();
    var myList2 = new MyList<string>();
    
    list1 = myList1; // error, not nominally equal
    list1 = myList2; // error, type mismatch
    ~~~~~
!!! error TS2322: Type 'MyList<string>' is not assignable to type 'List<number>'.
!!! error TS2322:   Types of property 'data' are incompatible.
!!! error TS2322:     Type 'string' is not assignable to type 'number'.
    
    list2 = myList1; // error, not nominally equal
    ~~~~~
!!! error TS2322: Type 'MyList<number>' is not assignable to type 'List<string>'.
!!! error TS2322:   Types of property 'data' are incompatible.
!!! error TS2322:     Type 'number' is not assignable to type 'string'.
    list2 = myList2; // error, type mismatch
    
    var rList1 = new List<List<number>>();
    var rMyList1 = new List<MyList<number>>();
    rList1 = rMyList1; // error, not nominally equal
    
    function foo<T extends List<number>, U extends MyList<number>>(t: T, u: U) {
        t = u; // error
        ~
!!! error TS2322: Type 'U' is not assignable to type 'T'.
!!! error TS2322:   Type 'MyList<number>' is not assignable to type 'T'.
        u = t; // error
        ~
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322:   Type 'List<number>' is not assignable to type 'U'.
    
        var a: List<number>;
        var b: MyList<number>;
        a = t; // ok
        a = u; // error
        b = t; // error
        b = u; // ok
    }
    
    function foo2<T extends U, U extends MyList<number>>(t: T, u: U) {
        t = u; // error
        ~
!!! error TS2322: Type 'U' is not assignable to type 'T'.
!!! error TS2322:   Type 'MyList<number>' is not assignable to type 'T'.
        u = t; // was error, ok after constraint made illegal, doesn't matter
    
        var a: List<number>;
        var b: MyList<number>;
    
        a = t; // error
        a = u; // error
        b = t; // ok
        b = u; // ok
    }