-
Notifications
You must be signed in to change notification settings - Fork 12.2k
/
instantiationExpressionErrors.js
299 lines (263 loc) · 6.38 KB
/
instantiationExpressionErrors.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//// [instantiationExpressionErrors.ts]
declare let f: { <T>(): T, g<U>(): U };
// Type arguments in member expressions
const a1 = f<number>; // { (): number; g<U>(): U; }
const a2 = f.g<number>; // () => number
const a3 = f<number>.g; // <U>() => U
const a4 = f<number>.g<number>; // () => number
const a5 = f['g']<number>; // () => number
// `[` is an expression starter and cannot immediately follow a type argument list
const a6 = f<number>['g']; // Error
const a7 = (f<number>)['g'];
// An `<` cannot immediately follow a type argument list
const a8 = f<number><number>; // Relational operator error
const a9 = (f<number>)<number>; // Error, no applicable signatures
// Type arguments with `?.` token
const b1 = f?.<number>; // Error, `(` expected
const b2 = f?.<number>();
const b3 = f<number>?.();
const b4 = f<number>?.<number>(); // Error, expected no type arguments
// Instantiation expression and binary operators
declare let g: (<T>(x: T) => T) | undefined;
const c1 = g<string> || ((x: string) => x);
const c2 = g<string> ?? ((x: string) => x);
const c3 = g<string> && ((x: string) => x);
// Parsed as function call, even though this differs from JavaScript
const x1 = f<true>
(true);
// Parsed as relational expressions
const r1 = f < true > true;
const r2 = f < true > +1;
const r3 = f < true > -1;
// All of the following are parsed as instantiation expressions
const x2 = f<true>
true;
const x3 = f<true>;
true;
const x4 = f<true>
if (true) {}
const x5 = f<true>
let yy = 0;
const x6 = f<true>
interface I {}
let x10 = f<true>
this.bar()
let x11 = f<true>
function bar() {}
let x12 = f<true>
class C {}
let x13 = f<true>
bar()
let x14 = f<true>
void bar()
class C1 {
static specialFoo = f<string>
static bar = 123
}
class C2 {
public specialFoo = f<string>
public bar = 123
}
class C3 {
private specialFoo = f<string>
private bar = 123
}
class C4 {
protected specialFoo = f<string>
protected bar = 123
}
// Repro from #49551
const enum MyVer { v1 = 1, v2 = 2 }
let ver = 21
const a = ver < (MyVer.v1 >= MyVer.v2 ? MyVer.v1 : MyVer.v2)
//// [instantiationExpressionErrors.js]
"use strict";
var _a, _b, _c;
// Type arguments in member expressions
var a1 = (f); // { (): number; g<U>(): U; }
var a2 = (f.g); // () => number
var a3 = f.g; // <U>() => U
var a4 = (f.g); // () => number
var a5 = (f['g']); // () => number
// `[` is an expression starter and cannot immediately follow a type argument list
var a6 = f < number > ['g']; // Error
var a7 = (f)['g'];
// An `<` cannot immediately follow a type argument list
var a8 = f < number > ; // Relational operator error
var a9 = ((f)); // Error, no applicable signatures
// Type arguments with `?.` token
var b1 = f === null || f === void 0 ? void 0 : f(); // Error, `(` expected
var b2 = f === null || f === void 0 ? void 0 : f();
var b3 = (_a = (f)) === null || _a === void 0 ? void 0 : _a();
var b4 = (_b = (f)) === null || _b === void 0 ? void 0 : _b(); // Error, expected no type arguments
var c1 = (g) || (function (x) { return x; });
var c2 = (_c = (g)) !== null && _c !== void 0 ? _c : (function (x) { return x; });
var c3 = (g) && (function (x) { return x; });
// Parsed as function call, even though this differs from JavaScript
var x1 = f(true);
// Parsed as relational expressions
var r1 = f < true > true;
var r2 = f < true > +1;
var r3 = f < true > -1;
// All of the following are parsed as instantiation expressions
var x2 = (f);
true;
var x3 = (f);
true;
var x4 = (f);
if (true) { }
var x5 = (f);
var yy = 0;
var x6 = (f);
var x10 = (f);
this.bar();
var x11 = (f);
function bar() { }
var x12 = (f);
var C = /** @class */ (function () {
function C() {
}
return C;
}());
var x13 = (f);
bar();
var x14 = (f);
void bar();
var C1 = /** @class */ (function () {
function C1() {
}
C1.specialFoo = (f);
C1.bar = 123;
return C1;
}());
var C2 = /** @class */ (function () {
function C2() {
this.specialFoo = (f);
this.bar = 123;
}
return C2;
}());
var C3 = /** @class */ (function () {
function C3() {
this.specialFoo = (f);
this.bar = 123;
}
return C3;
}());
var C4 = /** @class */ (function () {
function C4() {
this.specialFoo = (f);
this.bar = 123;
}
return C4;
}());
var ver = 21;
var a = ver < (1 /* MyVer.v1 */ >= 2 /* MyVer.v2 */ ? 1 /* MyVer.v1 */ : 2 /* MyVer.v2 */);
//// [instantiationExpressionErrors.d.ts]
declare let f: {
<T>(): T;
g<U>(): U;
};
declare const a1: {
(): number;
g<U>(): U;
};
declare const a2: () => number;
declare const a3: <U>() => U;
declare const a4: () => number;
declare const a5: () => number;
declare const a6: boolean;
declare const a7: <U>() => U;
declare const a8: boolean;
declare const a9: {
g<U>(): U;
};
declare const b1: number;
declare const b2: number;
declare const b3: number;
declare const b4: number;
declare let g: (<T>(x: T) => T) | undefined;
declare const c1: (x: string) => string;
declare const c2: (x: string) => string;
declare const c3: ((x: string) => string) | undefined;
declare const x1: true;
declare const r1: boolean;
declare const r2: boolean;
declare const r3: boolean;
declare const x2: {
(): true;
g<U>(): U;
};
declare const x3: {
(): true;
g<U>(): U;
};
declare const x4: {
(): true;
g<U>(): U;
};
declare const x5: {
(): true;
g<U>(): U;
};
declare let yy: number;
declare const x6: {
(): true;
g<U>(): U;
};
interface I {
}
declare let x10: {
(): true;
g<U>(): U;
};
declare let x11: {
(): true;
g<U>(): U;
};
declare function bar(): void;
declare let x12: {
(): true;
g<U>(): U;
};
declare class C {
}
declare let x13: {
(): true;
g<U>(): U;
};
declare let x14: {
(): true;
g<U>(): U;
};
declare class C1 {
static specialFoo: {
(): string;
g<U>(): U;
};
static bar: number;
}
declare class C2 {
specialFoo: {
(): string;
g<U>(): U;
};
bar: number;
}
declare class C3 {
private specialFoo;
private bar;
}
declare class C4 {
protected specialFoo: {
(): string;
g<U>(): U;
};
protected bar: number;
}
declare const enum MyVer {
v1 = 1,
v2 = 2
}
declare let ver: number;
declare const a: boolean;