File: unionTypeMembers.types

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 (191 lines) | stat: -rw-r--r-- 6,567 bytes parent folder | download | duplicates (4)
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
=== tests/cases/conformance/types/union/unionTypeMembers.ts ===
interface I1<T> {
    commonMethodType(a: string): string;
>commonMethodType : (a: string) => string
>a : string

    commonPropertyType: string;
>commonPropertyType : string

    commonMethodDifferentParameterType(a: string): string;
>commonMethodDifferentParameterType : (a: string) => string
>a : string

    commonMethodDifferentReturnType(a: string): string;
>commonMethodDifferentReturnType : (a: string) => string
>a : string

    commonPropertyDifferenType: string;
>commonPropertyDifferenType : string

    commonMethodWithTypeParameter(a: T): T;
>commonMethodWithTypeParameter : (a: T) => T
>a : T

    commonMethodWithOwnTypeParameter<U>(a: U): U;
>commonMethodWithOwnTypeParameter : <U>(a: U) => U
>a : U

    methodOnlyInI1(a: string): string;
>methodOnlyInI1 : (a: string) => string
>a : string

    propertyOnlyInI1: string;
>propertyOnlyInI1 : string
}

interface I2<T> {
    commonMethodType(a: string): string;
>commonMethodType : (a: string) => string
>a : string

    commonPropertyType: string;
>commonPropertyType : string

    commonMethodDifferentParameterType(a: number): number;
>commonMethodDifferentParameterType : (a: number) => number
>a : number

    commonMethodDifferentReturnType(a: string): number;
>commonMethodDifferentReturnType : (a: string) => number
>a : string

    commonPropertyDifferenType: number;
>commonPropertyDifferenType : number

    commonMethodWithTypeParameter(a: T): T;
>commonMethodWithTypeParameter : (a: T) => T
>a : T

    commonMethodWithOwnTypeParameter<U>(a: U): U;
>commonMethodWithOwnTypeParameter : <U>(a: U) => U
>a : U

    methodOnlyInI2(a: string): string;
>methodOnlyInI2 : (a: string) => string
>a : string

    propertyOnlyInI2: string;
>propertyOnlyInI2 : string
}

// a union type U has those members that are present in every one of its constituent types, 
// with types that are unions of the respective members in the constituent types
var x : I1<number> | I2<number>;
>x : I1<number> | I2<number>

var str: string;
>str : string

var num: number;
>num : number

var strOrNum: string | number;
>strOrNum : string | number

// If each type in U has a property P, U has a property P of a union type of the types of P from each type in U.
str = x.commonPropertyType; // string
>str = x.commonPropertyType : string
>str : string
>x.commonPropertyType : string
>x : I1<number> | I2<number>
>commonPropertyType : string

str = x.commonMethodType(str); // (a: string) => string so result should be string
>str = x.commonMethodType(str) : string
>str : string
>x.commonMethodType(str) : string
>x.commonMethodType : ((a: string) => string) | ((a: string) => string)
>x : I1<number> | I2<number>
>commonMethodType : ((a: string) => string) | ((a: string) => string)
>str : string

strOrNum = x.commonPropertyDifferenType;
>strOrNum = x.commonPropertyDifferenType : string | number
>strOrNum : string | number
>x.commonPropertyDifferenType : string | number
>x : I1<number> | I2<number>
>commonPropertyDifferenType : string | number

strOrNum = x.commonMethodDifferentReturnType(str); // string | union
>strOrNum = x.commonMethodDifferentReturnType(str) : string | number
>strOrNum : string | number
>x.commonMethodDifferentReturnType(str) : string | number
>x.commonMethodDifferentReturnType : ((a: string) => string) | ((a: string) => number)
>x : I1<number> | I2<number>
>commonMethodDifferentReturnType : ((a: string) => string) | ((a: string) => number)
>str : string

x.commonMethodDifferentParameterType; // No error - property exists
>x.commonMethodDifferentParameterType : ((a: string) => string) | ((a: number) => number)
>x : I1<number> | I2<number>
>commonMethodDifferentParameterType : ((a: string) => string) | ((a: number) => number)

x.commonMethodDifferentParameterType(strOrNum); // error - no call signatures because the type of this property is ((a: string) => string) | (a: number) => number
>x.commonMethodDifferentParameterType(strOrNum) : string | number
>x.commonMethodDifferentParameterType : ((a: string) => string) | ((a: number) => number)
>x : I1<number> | I2<number>
>commonMethodDifferentParameterType : ((a: string) => string) | ((a: number) => number)
>strOrNum : string | number

                                                // and the call signatures arent identical
num = x.commonMethodWithTypeParameter(num);
>num = x.commonMethodWithTypeParameter(num) : number
>num : number
>x.commonMethodWithTypeParameter(num) : number
>x.commonMethodWithTypeParameter : ((a: number) => number) | ((a: number) => number)
>x : I1<number> | I2<number>
>commonMethodWithTypeParameter : ((a: number) => number) | ((a: number) => number)
>num : number

num = x.commonMethodWithOwnTypeParameter(num);
>num = x.commonMethodWithOwnTypeParameter(num) : number
>num : number
>x.commonMethodWithOwnTypeParameter(num) : number
>x.commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>x : I1<number> | I2<number>
>commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>num : number

str = x.commonMethodWithOwnTypeParameter(str);
>str = x.commonMethodWithOwnTypeParameter(str) : string
>str : string
>x.commonMethodWithOwnTypeParameter(str) : string
>x.commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>x : I1<number> | I2<number>
>commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>str : string

strOrNum = x.commonMethodWithOwnTypeParameter(strOrNum);
>strOrNum = x.commonMethodWithOwnTypeParameter(strOrNum) : string | number
>strOrNum : string | number
>x.commonMethodWithOwnTypeParameter(strOrNum) : string | number
>x.commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>x : I1<number> | I2<number>
>commonMethodWithOwnTypeParameter : (<U>(a: U) => U) | (<U>(a: U) => U)
>strOrNum : string | number

x.propertyOnlyInI1; // error
>x.propertyOnlyInI1 : any
>x : I1<number> | I2<number>
>propertyOnlyInI1 : any

x.propertyOnlyInI2; // error
>x.propertyOnlyInI2 : any
>x : I1<number> | I2<number>
>propertyOnlyInI2 : any

x.methodOnlyInI1("hello"); // error
>x.methodOnlyInI1("hello") : any
>x.methodOnlyInI1 : any
>x : I1<number> | I2<number>
>methodOnlyInI1 : any
>"hello" : "hello"

x.methodOnlyInI2(10); // error
>x.methodOnlyInI2(10) : any
>x.methodOnlyInI2 : any
>x : I1<number> | I2<number>
>methodOnlyInI2 : any
>10 : 10