-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
Copy patharrayBestCommonTypes.js
233 lines (209 loc) · 9.34 KB
/
arrayBestCommonTypes.js
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//// [arrayBestCommonTypes.ts]
module EmptyTypes {
interface iface { }
class base implements iface { }
class base2 implements iface { }
class derived extends base { }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
module NonEmptyTypes {
interface iface { x: string; }
class base implements iface { x: string; y: string; }
class base2 implements iface { x: string; z: string; }
class derived extends base { a: string; }
class f {
public voidIfAny(x: boolean, y?: boolean): number;
public voidIfAny(x: string, y?: boolean): number;
public voidIfAny(x: number, y?: boolean): number;
public voidIfAny(x: any, y = false): any { return null; }
public x() {
<number>(this.voidIfAny([4, 2][0]));
<number>(this.voidIfAny([4, 2, undefined][0]));
<number>(this.voidIfAny([undefined, 2, 4][0]));
<number>(this.voidIfAny([null, 2, 4][0]));
<number>(this.voidIfAny([2, 4, null][0]));
<number>(this.voidIfAny([undefined, 4, null][0]));
<number>(this.voidIfAny(['', "q"][0]));
<number>(this.voidIfAny(['', "q", undefined][0]));
<number>(this.voidIfAny([undefined, "q", ''][0]));
<number>(this.voidIfAny([null, "q", ''][0]));
<number>(this.voidIfAny(["q", '', null][0]));
<number>(this.voidIfAny([undefined, '', null][0]));
<number>(this.voidIfAny([[3, 4], [null]][0][0]));
var t1: { x: number; y: base; }[] = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2: { x: boolean; y: base; }[] = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3: { x: string; y: base; }[] = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj: any = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj: iface = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
}
}
}
//// [arrayBestCommonTypes.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var EmptyTypes;
(function (EmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(EmptyTypes || (EmptyTypes = {}));
var NonEmptyTypes;
(function (NonEmptyTypes) {
var base = (function () {
function base() {
}
return base;
})();
var base2 = (function () {
function base2() {
}
return base2;
})();
var derived = (function (_super) {
__extends(derived, _super);
function derived() {
_super.apply(this, arguments);
}
return derived;
})(base);
var f = (function () {
function f() {
}
f.prototype.voidIfAny = function (x, y) {
if (y === void 0) { y = false; }
return null;
};
f.prototype.x = function () {
(this.voidIfAny([4, 2][0]));
(this.voidIfAny([4, 2, undefined][0]));
(this.voidIfAny([undefined, 2, 4][0]));
(this.voidIfAny([null, 2, 4][0]));
(this.voidIfAny([2, 4, null][0]));
(this.voidIfAny([undefined, 4, null][0]));
(this.voidIfAny(['', "q"][0]));
(this.voidIfAny(['', "q", undefined][0]));
(this.voidIfAny([undefined, "q", ''][0]));
(this.voidIfAny([null, "q", ''][0]));
(this.voidIfAny(["q", '', null][0]));
(this.voidIfAny([undefined, '', null][0]));
(this.voidIfAny([[3, 4], [null]][0][0]));
var t1 = [{ x: 7, y: new derived() }, { x: 5, y: new base() }];
var t2 = [{ x: true, y: new derived() }, { x: false, y: new base() }];
var t3 = [{ x: undefined, y: new base() }, { x: '', y: new derived() }];
var anyObj = null;
// Order matters here so test all the variants
var a1 = [{ x: 0, y: 'a' }, { x: 'a', y: 'a' }, { x: anyObj, y: 'a' }];
var a2 = [{ x: anyObj, y: 'a' }, { x: 0, y: 'a' }, { x: 'a', y: 'a' }];
var a3 = [{ x: 0, y: 'a' }, { x: anyObj, y: 'a' }, { x: 'a', y: 'a' }];
var ifaceObj = null;
var baseObj = new base();
var base2Obj = new base2();
var b1 = [baseObj, base2Obj, ifaceObj];
var b2 = [base2Obj, baseObj, ifaceObj];
var b3 = [baseObj, ifaceObj, base2Obj];
var b4 = [ifaceObj, baseObj, base2Obj];
};
return f;
})();
})(NonEmptyTypes || (NonEmptyTypes = {}));