File: contextualTypeWithUnionTypeObjectLiteral.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 (130 lines) | stat: -rw-r--r-- 9,159 bytes parent folder | download | duplicates (2)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(14,5): error TS2322: Type '{ prop: string | number; }' is not assignable to type '{ prop: string; } | { prop: number; }'.
  Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
    Types of property 'prop' are incompatible.
      Type 'string | number' is not assignable to type 'number'.
        Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(20,5): error TS2322: Type '{ prop: string | number; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
  Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
    Types of property 'prop' are incompatible.
      Type 'string | number' is not assignable to type 'number'.
        Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(21,5): error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
  Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; }'.
    Types of property 'prop' are incompatible.
      Type 'string | number' is not assignable to type 'number'.
        Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(25,5): error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
  Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
    Types of property 'prop' are incompatible.
      Type 'string | number' is not assignable to type 'number'.
        Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(29,5): error TS2322: Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
  Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
    Types of property 'prop' are incompatible.
      Type 'string | number' is not assignable to type 'number'.
        Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts(57,5): error TS2322: Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I11 | I21'.
  Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I21'.
    Types of property 'commonMethodDifferentReturnType' are incompatible.
      Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => number'.
        Type 'string | number' is not assignable to type 'number'.
          Type 'string' is not assignable to type 'number'.


==== tests/cases/conformance/types/union/contextualTypeWithUnionTypeObjectLiteral.ts (6 errors) ====
    var str: string;
    var num: number;
    var strOrNumber: string | number = str || num;
    var objStr: { prop: string };
    var objNum: { prop: number };
    var objStrOrNum1: { prop: string } | { prop: number } = objStr || objNum;
    var objStrOrNum2: { prop: string | number } = objStr || objNum;
    // Below is error because :
    // Spec says:
    // S is a union type and each constituent type of S is assignable to T.
    // T is a union type and S is assignable to at least one constituent type of T.
    // In case of objStrOrNum3, the S is not union Type but object Literal so we go to next step. 
    // Since T is union Type we only allow the assignment of either object with property of type string or object with property of type number but do not allow object with property of type string | number
    var objStrOrNum3: { prop: string } | { prop: number } = {
        ~~~~~~~~~~~~
!!! error TS2322: Type '{ prop: string | number; }' is not assignable to type '{ prop: string; } | { prop: number; }'.
!!! error TS2322:   Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
!!! error TS2322:     Types of property 'prop' are incompatible.
!!! error TS2322:       Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
        prop: strOrNumber
    };
    var objStrOrNum4: { prop: string | number } = {
        prop: strOrNumber
    };
    var objStrOrNum5: { prop: string; anotherP: string; } | { prop: number } = { prop: strOrNumber };
        ~~~~~~~~~~~~
!!! error TS2322: Type '{ prop: string | number; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
!!! error TS2322:   Type '{ prop: string | number; }' is not assignable to type '{ prop: number; }'.
!!! error TS2322:     Types of property 'prop' are incompatible.
!!! error TS2322:       Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
    var objStrOrNum6: { prop: string; anotherP: string; } | { prop: number } = {
        ~~~~~~~~~~~~
!!! error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; }'.
!!! error TS2322:   Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; }'.
!!! error TS2322:     Types of property 'prop' are incompatible.
!!! error TS2322:       Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
        prop: strOrNumber,
        anotherP: str
    };
    var objStrOrNum7: { prop: string; anotherP: string; } | { prop: number; anotherP1: number } = {
        ~~~~~~~~~~~~
!!! error TS2322: Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
!!! error TS2322:   Type '{ prop: string | number; anotherP: string; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
!!! error TS2322:     Types of property 'prop' are incompatible.
!!! error TS2322:       Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
        prop: strOrNumber,
        anotherP: str
    };
    var objStrOrNum8: { prop: string; anotherP: string; } | { prop: number; anotherP1: number } = {
        ~~~~~~~~~~~~
!!! error TS2322: Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: string; anotherP: string; } | { prop: number; anotherP1: number; }'.
!!! error TS2322:   Type '{ prop: string | number; anotherP: string; anotherP1: number; }' is not assignable to type '{ prop: number; anotherP1: number; }'.
!!! error TS2322:     Types of property 'prop' are incompatible.
!!! error TS2322:       Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:         Type 'string' is not assignable to type 'number'.
        prop: strOrNumber,
        anotherP: str,
        anotherP1: num
    };
    interface I11 {
        commonMethodDifferentReturnType(a: string, b: number): string;
    }
    interface I21 {
        commonMethodDifferentReturnType(a: string, b: number): number;
    }
    var i11: I11;
    var i21: I21;
    var i11Ori21: I11 | I21 = i11;
    var i11Ori21: I11 | I21 = i21;
    var i11Ori21: I11 | I21 = { // Like i1
        commonMethodDifferentReturnType: (a, b) => {
            var z = a.charAt(b);
            return z;
        },
    };
    var i11Ori21: I11 | I21 = { // Like i2
        commonMethodDifferentReturnType: (a, b) => {
            var z = a.charCodeAt(b);
            return z;
        },
    };
    var strOrNumber: string | number;
    var i11Ori21: I11 | I21 = { // Like i1 and i2 both
        ~~~~~~~~
!!! error TS2322: Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I11 | I21'.
!!! error TS2322:   Type '{ commonMethodDifferentReturnType: (a: string, b: number) => string | number; }' is not assignable to type 'I21'.
!!! error TS2322:     Types of property 'commonMethodDifferentReturnType' are incompatible.
!!! error TS2322:       Type '(a: string, b: number) => string | number' is not assignable to type '(a: string, b: number) => number'.
!!! error TS2322:         Type 'string | number' is not assignable to type 'number'.
!!! error TS2322:           Type 'string' is not assignable to type 'number'.
        commonMethodDifferentReturnType: (a, b) => strOrNumber,
    };