-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Expand file tree
/
Copy pathcontextuallyTypedParametersWithInitializers.js
More file actions
235 lines (213 loc) · 6.18 KB
/
contextuallyTypedParametersWithInitializers.js
File metadata and controls
235 lines (213 loc) · 6.18 KB
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
//// [contextuallyTypedParametersWithInitializers.ts]
declare function id1<T>(input: T): T;
declare function id2<T extends (x: any) => any>(input: T): T;
declare function id3<T extends (x: { foo: any }) => any>(input: T): T;
declare function id4<T extends (x: { foo?: number }) => any>(input: T): T;
declare function id5<T extends (x?: number) => any>(input: T): T;
const f10 = function ({ foo = 42 }) { return foo };
const f11 = id1(function ({ foo = 42 }) { return foo });
const f12 = id2(function ({ foo = 42 }) { return foo });
const f13 = id3(function ({ foo = 42 }) { return foo });
const f14 = id4(function ({ foo = 42 }) { return foo });
const f20 = function (foo = 42) { return foo };
const f21 = id1(function (foo = 42) { return foo });
const f22 = id2(function (foo = 42) { return foo });
const f25 = id5(function (foo = 42) { return foo });
const f1 = (x = 1) => 0; // number
const f2: any = (x = 1) => 0; // number
const f3: unknown = (x = 1) => 0; // number
const f4: Function = (x = 1) => 0; // number
const f5: (...args: any[]) => any = (x = 1) => 0; // any
const f6: () => any = (x = 1) => 0; // number
const f7: () => any = (x?) => 0; // Implicit any error
const f8: () => any = (...x) => 0; // []
declare function g1<T>(x: T): T;
declare function g2<T extends any>(x: T): T;
declare function g3<T extends unknown>(x: T): T;
declare function g4<T extends Function>(x: T): T;
declare function g5<T extends (...args: any[]) => any>(x: T): T;
declare function g6<T extends () => any>(x: T): T;
g1((x = 1) => 0); // number
g2((x = 1) => 0); // number
g3((x = 1) => 0); // number
g4((x = 1) => 0); // number
g5((x = 1) => 0); // any
g6((x = 1) => 0); // number
g6((x?) => 0); // Implicit any error
g6((...x) => 0); // []
// Repro from #28816
function id<T>(input: T): T { return input }
function getFoo ({ foo = 42 }) {
return foo;
}
const newGetFoo = id(getFoo);
const newGetFoo2 = id(function getFoo ({ foo = 42 }) {
return foo;
});
// Repro from comment in #30840
declare function memoize<F extends Function>(func: F): F;
function add(x: number, y = 0): number {
return x + y;
}
const memoizedAdd = memoize(add);
const add2 = (x: number, y = 0): number => x + y;
const memoizedAdd2 = memoize(add2);
const memoizedAdd3 = memoize((x: number, y = 0): number => x + y);
// Repro from #36052
declare function execute(script: string | Function): Promise<string>;
export function executeSomething() {
return execute((root: HTMLElement, debug = true) => {
if (debug) {
root.innerHTML = '';
}
});
}
const fz1 = (debug = true) => false;
const fz2: Function = (debug = true) => false;
//// [contextuallyTypedParametersWithInitializers.js]
"use strict";
exports.__esModule = true;
var f10 = function (_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
};
var f11 = id1(function (_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
});
var f12 = id2(function (_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
});
var f13 = id3(function (_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
});
var f14 = id4(function (_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
});
var f20 = function (foo) {
if (foo === void 0) { foo = 42; }
return foo;
};
var f21 = id1(function (foo) {
if (foo === void 0) { foo = 42; }
return foo;
});
var f22 = id2(function (foo) {
if (foo === void 0) { foo = 42; }
return foo;
});
var f25 = id5(function (foo) {
if (foo === void 0) { foo = 42; }
return foo;
});
var f1 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // number
var f2 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // number
var f3 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // number
var f4 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // number
var f5 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // any
var f6 = function (x) {
if (x === void 0) { x = 1; }
return 0;
}; // number
var f7 = function (x) { return 0; }; // Implicit any error
var f8 = function () {
var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
x[_i] = arguments[_i];
}
return 0;
}; // []
g1(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // number
g2(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // number
g3(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // number
g4(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // number
g5(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // any
g6(function (x) {
if (x === void 0) { x = 1; }
return 0;
}); // number
g6(function (x) { return 0; }); // Implicit any error
g6(function () {
var x = [];
for (var _i = 0; _i < arguments.length; _i++) {
x[_i] = arguments[_i];
}
return 0;
}); // []
// Repro from #28816
function id(input) { return input; }
function getFoo(_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
}
var newGetFoo = id(getFoo);
var newGetFoo2 = id(function getFoo(_a) {
var _b = _a.foo, foo = _b === void 0 ? 42 : _b;
return foo;
});
function add(x, y) {
if (y === void 0) { y = 0; }
return x + y;
}
var memoizedAdd = memoize(add);
var add2 = function (x, y) {
if (y === void 0) { y = 0; }
return x + y;
};
var memoizedAdd2 = memoize(add2);
var memoizedAdd3 = memoize(function (x, y) {
if (y === void 0) { y = 0; }
return x + y;
});
function executeSomething() {
return execute(function (root, debug) {
if (debug === void 0) { debug = true; }
if (debug) {
root.innerHTML = '';
}
});
}
exports.executeSomething = executeSomething;
var fz1 = function (debug) {
if (debug === void 0) { debug = true; }
return false;
};
var fz2 = function (debug) {
if (debug === void 0) { debug = true; }
return false;
};
//// [contextuallyTypedParametersWithInitializers.d.ts]
export declare function executeSomething(): Promise<string>;