bun-types 1.2.20-canary.20250731T140826 → 1.2.20-canary.20250802T140550

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,669 @@
1
+ /*
2
+ Copyright 2024 Misha Kaletsky
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+
17
+ Apache License
18
+ Version 2.0, January 2004
19
+ http://www.apache.org/licenses/
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
193
+ */
194
+
195
+ import type {
196
+ IsNever,
197
+ StrictEqualUsingTSInternalIdenticalToOperator,
198
+ UnionToIntersection,
199
+ UnionToTuple,
200
+ } from "./utils";
201
+ /**
202
+ * The simple(ish) way to get overload info from a function
203
+ * {@linkcode FunctionType}. Recent versions of TypeScript will match any
204
+ * function against a generic 10-overload type, filling in slots with
205
+ * duplicates of the function. So, we can just match against a single type
206
+ * and get all the overloads.
207
+ *
208
+ * For older versions of TypeScript, we'll need to painstakingly do
209
+ * ten separate matches.
210
+ */
211
+ export type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
212
+ (...args: infer A1): infer R1;
213
+ (...args: infer A2): infer R2;
214
+ (...args: infer A3): infer R3;
215
+ (...args: infer A4): infer R4;
216
+ (...args: infer A5): infer R5;
217
+ (...args: infer A6): infer R6;
218
+ (...args: infer A7): infer R7;
219
+ (...args: infer A8): infer R8;
220
+ (...args: infer A9): infer R9;
221
+ (...args: infer A10): infer R10;
222
+ }
223
+ ?
224
+ | ((...p: A1) => R1)
225
+ | ((...p: A2) => R2)
226
+ | ((...p: A3) => R3)
227
+ | ((...p: A4) => R4)
228
+ | ((...p: A5) => R5)
229
+ | ((...p: A6) => R6)
230
+ | ((...p: A7) => R7)
231
+ | ((...p: A8) => R8)
232
+ | ((...p: A9) => R9)
233
+ | ((...p: A10) => R10)
234
+ : never;
235
+ /**
236
+ * A function with `unknown` parameters and return type.
237
+ */
238
+ export type UnknownFunction = (...args: unknown[]) => unknown;
239
+ /**
240
+ * `true` iff {@linkcode FunctionType} is
241
+ * equivalent to `(...args: unknown[]) => unknown`,
242
+ * which is what an overload variant looks like for a non-existent overload.
243
+ * This is useful because older versions of TypeScript end up with
244
+ * 9 "useless" overloads and one real one for parameterless/generic functions.
245
+ *
246
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
247
+ */
248
+ export type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<
249
+ FunctionType,
250
+ UnknownFunction
251
+ >;
252
+ /**
253
+ * Old versions of TypeScript can sometimes seem to refuse to separate out
254
+ * union members unless you put them each in a pointless tuple and add an
255
+ * extra `infer X` expression. There may be a better way to work around this
256
+ * problem, but since it's not a problem in newer versions of TypeScript,
257
+ * it's not a priority right now.
258
+ */
259
+ export type Tuplify<Union> = Union extends infer X ? [X] : never;
260
+ /**
261
+ * For older versions of TypeScript, we need two separate workarounds
262
+ * to get overload info. First, we need need to use
263
+ * {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
264
+ * functions with 1-10 overloads. Then, we need to filter out the
265
+ * "useless" overloads that are present in older versions of TypeScript,
266
+ * for parameterless functions. To do this we use
267
+ * {@linkcode IsUselessOverloadInfo} to remove useless overloads.
268
+ *
269
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
270
+ */
271
+ export type TSPre53OverloadsInfoUnion<FunctionType> =
272
+ Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup
273
+ ? Tup extends [infer Fn]
274
+ ? IsUselessOverloadInfo<Fn> extends true
275
+ ? never
276
+ : Fn
277
+ : never
278
+ : never;
279
+ /**
280
+ * For versions of TypeScript below 5.3, we need to check for 10 overloads,
281
+ * then 9, then 8, etc., to get a union of the overload variants.
282
+ */
283
+ export type DecreasingOverloadsInfoUnion<F> = F extends {
284
+ (...args: infer A1): infer R1;
285
+ (...args: infer A2): infer R2;
286
+ (...args: infer A3): infer R3;
287
+ (...args: infer A4): infer R4;
288
+ (...args: infer A5): infer R5;
289
+ (...args: infer A6): infer R6;
290
+ (...args: infer A7): infer R7;
291
+ (...args: infer A8): infer R8;
292
+ (...args: infer A9): infer R9;
293
+ (...args: infer A10): infer R10;
294
+ }
295
+ ?
296
+ | ((...p: A1) => R1)
297
+ | ((...p: A2) => R2)
298
+ | ((...p: A3) => R3)
299
+ | ((...p: A4) => R4)
300
+ | ((...p: A5) => R5)
301
+ | ((...p: A6) => R6)
302
+ | ((...p: A7) => R7)
303
+ | ((...p: A8) => R8)
304
+ | ((...p: A9) => R9)
305
+ | ((...p: A10) => R10)
306
+ : F extends {
307
+ (...args: infer A1): infer R1;
308
+ (...args: infer A2): infer R2;
309
+ (...args: infer A3): infer R3;
310
+ (...args: infer A4): infer R4;
311
+ (...args: infer A5): infer R5;
312
+ (...args: infer A6): infer R6;
313
+ (...args: infer A7): infer R7;
314
+ (...args: infer A8): infer R8;
315
+ (...args: infer A9): infer R9;
316
+ }
317
+ ?
318
+ | ((...p: A1) => R1)
319
+ | ((...p: A2) => R2)
320
+ | ((...p: A3) => R3)
321
+ | ((...p: A4) => R4)
322
+ | ((...p: A5) => R5)
323
+ | ((...p: A6) => R6)
324
+ | ((...p: A7) => R7)
325
+ | ((...p: A8) => R8)
326
+ | ((...p: A9) => R9)
327
+ : F extends {
328
+ (...args: infer A1): infer R1;
329
+ (...args: infer A2): infer R2;
330
+ (...args: infer A3): infer R3;
331
+ (...args: infer A4): infer R4;
332
+ (...args: infer A5): infer R5;
333
+ (...args: infer A6): infer R6;
334
+ (...args: infer A7): infer R7;
335
+ (...args: infer A8): infer R8;
336
+ }
337
+ ?
338
+ | ((...p: A1) => R1)
339
+ | ((...p: A2) => R2)
340
+ | ((...p: A3) => R3)
341
+ | ((...p: A4) => R4)
342
+ | ((...p: A5) => R5)
343
+ | ((...p: A6) => R6)
344
+ | ((...p: A7) => R7)
345
+ | ((...p: A8) => R8)
346
+ : F extends {
347
+ (...args: infer A1): infer R1;
348
+ (...args: infer A2): infer R2;
349
+ (...args: infer A3): infer R3;
350
+ (...args: infer A4): infer R4;
351
+ (...args: infer A5): infer R5;
352
+ (...args: infer A6): infer R6;
353
+ (...args: infer A7): infer R7;
354
+ }
355
+ ?
356
+ | ((...p: A1) => R1)
357
+ | ((...p: A2) => R2)
358
+ | ((...p: A3) => R3)
359
+ | ((...p: A4) => R4)
360
+ | ((...p: A5) => R5)
361
+ | ((...p: A6) => R6)
362
+ | ((...p: A7) => R7)
363
+ : F extends {
364
+ (...args: infer A1): infer R1;
365
+ (...args: infer A2): infer R2;
366
+ (...args: infer A3): infer R3;
367
+ (...args: infer A4): infer R4;
368
+ (...args: infer A5): infer R5;
369
+ (...args: infer A6): infer R6;
370
+ }
371
+ ?
372
+ | ((...p: A1) => R1)
373
+ | ((...p: A2) => R2)
374
+ | ((...p: A3) => R3)
375
+ | ((...p: A4) => R4)
376
+ | ((...p: A5) => R5)
377
+ | ((...p: A6) => R6)
378
+ : F extends {
379
+ (...args: infer A1): infer R1;
380
+ (...args: infer A2): infer R2;
381
+ (...args: infer A3): infer R3;
382
+ (...args: infer A4): infer R4;
383
+ (...args: infer A5): infer R5;
384
+ }
385
+ ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5)
386
+ : F extends {
387
+ (...args: infer A1): infer R1;
388
+ (...args: infer A2): infer R2;
389
+ (...args: infer A3): infer R3;
390
+ (...args: infer A4): infer R4;
391
+ }
392
+ ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4)
393
+ : F extends {
394
+ (...args: infer A1): infer R1;
395
+ (...args: infer A2): infer R2;
396
+ (...args: infer A3): infer R3;
397
+ }
398
+ ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3)
399
+ : F extends {
400
+ (...args: infer A1): infer R1;
401
+ (...args: infer A2): infer R2;
402
+ }
403
+ ? ((...p: A1) => R1) | ((...p: A2) => R2)
404
+ : F extends (...args: infer A1) => infer R1
405
+ ? (...p: A1) => R1
406
+ : never;
407
+ /**
408
+ * Get a union of overload variants for a function {@linkcode FunctionType}.
409
+ * Does a check for whether we can do the one-shot
410
+ * 10-overload matcher (which works for ts\>5.3), and if not,
411
+ * falls back to the more complicated utility.
412
+ */
413
+ export type OverloadsInfoUnion<FunctionType> =
414
+ IsNever<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true
415
+ ? TSPre53OverloadsInfoUnion<FunctionType>
416
+ : TSPost53OverloadsInfoUnion<FunctionType>;
417
+ /**
418
+ * Allows inferring any function using the `infer` keyword.
419
+ */
420
+ export type InferFunctionType<FunctionType extends (...args: any) => any> = FunctionType;
421
+ /**
422
+ * A union type of the parameters allowed for any
423
+ * overload of function {@linkcode FunctionType}.
424
+ */
425
+ export type OverloadParameters<FunctionType> =
426
+ OverloadsInfoUnion<FunctionType> extends InferFunctionType<infer Fn> ? Parameters<Fn> : never;
427
+ /**
428
+ * A union type of the return types for any overload of
429
+ * function {@linkcode FunctionType}.
430
+ */
431
+ export type OverloadReturnTypes<FunctionType> =
432
+ OverloadsInfoUnion<FunctionType> extends InferFunctionType<infer Fn> ? ReturnType<Fn> : never;
433
+ /**
434
+ * Takes an overload variants {@linkcode Union},
435
+ * produced from {@linkcode OverloadsInfoUnion} and rejects
436
+ * the ones incompatible with parameters {@linkcode Args}.
437
+ */
438
+ export type SelectOverloadsInfo<Union extends UnknownFunction, Args extends unknown[]> =
439
+ Union extends InferFunctionType<infer Fn> ? (Args extends Parameters<Fn> ? Fn : never) : never;
440
+ /**
441
+ * Creates a new overload (an intersection type) from an existing one,
442
+ * which only includes variant(s) which can accept
443
+ * {@linkcode Args} as parameters.
444
+ */
445
+ export type OverloadsNarrowedByParameters<
446
+ FunctionType,
447
+ Args extends OverloadParameters<FunctionType>,
448
+ > = UnionToIntersection<SelectOverloadsInfo<OverloadsInfoUnion<FunctionType>, Args>>;
449
+ /**
450
+ * The simple(ish) way to get overload info from a constructor
451
+ * {@linkcode ConstructorType}. Recent versions of TypeScript will match any
452
+ * constructor against a generic 10-overload type, filling in slots with
453
+ * duplicates of the constructor. So, we can just match against a single type
454
+ * and get all the overloads.
455
+ *
456
+ * For older versions of TypeScript,
457
+ * we'll need to painstakingly do ten separate matches.
458
+ */
459
+ export type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
460
+ new (...args: infer A1): infer R1;
461
+ new (...args: infer A2): infer R2;
462
+ new (...args: infer A3): infer R3;
463
+ new (...args: infer A4): infer R4;
464
+ new (...args: infer A5): infer R5;
465
+ new (...args: infer A6): infer R6;
466
+ new (...args: infer A7): infer R7;
467
+ new (...args: infer A8): infer R8;
468
+ new (...args: infer A9): infer R9;
469
+ new (...args: infer A10): infer R10;
470
+ }
471
+ ?
472
+ | (new (...p: A1) => R1)
473
+ | (new (...p: A2) => R2)
474
+ | (new (...p: A3) => R3)
475
+ | (new (...p: A4) => R4)
476
+ | (new (...p: A5) => R5)
477
+ | (new (...p: A6) => R6)
478
+ | (new (...p: A7) => R7)
479
+ | (new (...p: A8) => R8)
480
+ | (new (...p: A9) => R9)
481
+ | (new (...p: A10) => R10)
482
+ : never;
483
+ /**
484
+ * A constructor function with `unknown` parameters and return type.
485
+ */
486
+ export type UnknownConstructor = new (...args: unknown[]) => unknown;
487
+ /**
488
+ * Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
489
+ */
490
+ export type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<
491
+ FunctionType,
492
+ UnknownConstructor
493
+ >;
494
+ /**
495
+ * For older versions of TypeScript, we need two separate workarounds to
496
+ * get constructor overload info. First, we need need to use
497
+ * {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
498
+ * info for constructors with 1-10 overloads. Then, we need to filter out the
499
+ * "useless" overloads that are present in older versions of TypeScript,
500
+ * for parameterless constructors. To do this we use
501
+ * {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
502
+ *
503
+ * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
504
+ */
505
+ export type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> =
506
+ Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup
507
+ ? Tup extends [infer Ctor]
508
+ ? IsUselessConstructorOverloadInfo<Ctor> extends true
509
+ ? never
510
+ : Ctor
511
+ : never
512
+ : never;
513
+ /**
514
+ * For versions of TypeScript below 5.3, we need to check for 10 overloads,
515
+ * then 9, then 8, etc., to get a union of the overload variants.
516
+ */
517
+ export type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
518
+ new (...args: infer A1): infer R1;
519
+ new (...args: infer A2): infer R2;
520
+ new (...args: infer A3): infer R3;
521
+ new (...args: infer A4): infer R4;
522
+ new (...args: infer A5): infer R5;
523
+ new (...args: infer A6): infer R6;
524
+ new (...args: infer A7): infer R7;
525
+ new (...args: infer A8): infer R8;
526
+ new (...args: infer A9): infer R9;
527
+ new (...args: infer A10): infer R10;
528
+ }
529
+ ?
530
+ | (new (...p: A1) => R1)
531
+ | (new (...p: A2) => R2)
532
+ | (new (...p: A3) => R3)
533
+ | (new (...p: A4) => R4)
534
+ | (new (...p: A5) => R5)
535
+ | (new (...p: A6) => R6)
536
+ | (new (...p: A7) => R7)
537
+ | (new (...p: A8) => R8)
538
+ | (new (...p: A9) => R9)
539
+ | (new (...p: A10) => R10)
540
+ : ConstructorType extends {
541
+ new (...args: infer A1): infer R1;
542
+ new (...args: infer A2): infer R2;
543
+ new (...args: infer A3): infer R3;
544
+ new (...args: infer A4): infer R4;
545
+ new (...args: infer A5): infer R5;
546
+ new (...args: infer A6): infer R6;
547
+ new (...args: infer A7): infer R7;
548
+ new (...args: infer A8): infer R8;
549
+ new (...args: infer A9): infer R9;
550
+ }
551
+ ?
552
+ | (new (...p: A1) => R1)
553
+ | (new (...p: A2) => R2)
554
+ | (new (...p: A3) => R3)
555
+ | (new (...p: A4) => R4)
556
+ | (new (...p: A5) => R5)
557
+ | (new (...p: A6) => R6)
558
+ | (new (...p: A7) => R7)
559
+ | (new (...p: A8) => R8)
560
+ | (new (...p: A9) => R9)
561
+ : ConstructorType extends {
562
+ new (...args: infer A1): infer R1;
563
+ new (...args: infer A2): infer R2;
564
+ new (...args: infer A3): infer R3;
565
+ new (...args: infer A4): infer R4;
566
+ new (...args: infer A5): infer R5;
567
+ new (...args: infer A6): infer R6;
568
+ new (...args: infer A7): infer R7;
569
+ new (...args: infer A8): infer R8;
570
+ }
571
+ ?
572
+ | (new (...p: A1) => R1)
573
+ | (new (...p: A2) => R2)
574
+ | (new (...p: A3) => R3)
575
+ | (new (...p: A4) => R4)
576
+ | (new (...p: A5) => R5)
577
+ | (new (...p: A6) => R6)
578
+ | (new (...p: A7) => R7)
579
+ | (new (...p: A8) => R8)
580
+ : ConstructorType extends {
581
+ new (...args: infer A1): infer R1;
582
+ new (...args: infer A2): infer R2;
583
+ new (...args: infer A3): infer R3;
584
+ new (...args: infer A4): infer R4;
585
+ new (...args: infer A5): infer R5;
586
+ new (...args: infer A6): infer R6;
587
+ new (...args: infer A7): infer R7;
588
+ }
589
+ ?
590
+ | (new (...p: A1) => R1)
591
+ | (new (...p: A2) => R2)
592
+ | (new (...p: A3) => R3)
593
+ | (new (...p: A4) => R4)
594
+ | (new (...p: A5) => R5)
595
+ | (new (...p: A6) => R6)
596
+ | (new (...p: A7) => R7)
597
+ : ConstructorType extends {
598
+ new (...args: infer A1): infer R1;
599
+ new (...args: infer A2): infer R2;
600
+ new (...args: infer A3): infer R3;
601
+ new (...args: infer A4): infer R4;
602
+ new (...args: infer A5): infer R5;
603
+ new (...args: infer A6): infer R6;
604
+ }
605
+ ?
606
+ | (new (...p: A1) => R1)
607
+ | (new (...p: A2) => R2)
608
+ | (new (...p: A3) => R3)
609
+ | (new (...p: A4) => R4)
610
+ | (new (...p: A5) => R5)
611
+ | (new (...p: A6) => R6)
612
+ : ConstructorType extends {
613
+ new (...args: infer A1): infer R1;
614
+ new (...args: infer A2): infer R2;
615
+ new (...args: infer A3): infer R3;
616
+ new (...args: infer A4): infer R4;
617
+ new (...args: infer A5): infer R5;
618
+ }
619
+ ?
620
+ | (new (...p: A1) => R1)
621
+ | (new (...p: A2) => R2)
622
+ | (new (...p: A3) => R3)
623
+ | (new (...p: A4) => R4)
624
+ | (new (...p: A5) => R5)
625
+ : ConstructorType extends {
626
+ new (...args: infer A1): infer R1;
627
+ new (...args: infer A2): infer R2;
628
+ new (...args: infer A3): infer R3;
629
+ new (...args: infer A4): infer R4;
630
+ }
631
+ ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4)
632
+ : ConstructorType extends {
633
+ new (...args: infer A1): infer R1;
634
+ new (...args: infer A2): infer R2;
635
+ new (...args: infer A3): infer R3;
636
+ }
637
+ ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3)
638
+ : ConstructorType extends {
639
+ new (...args: infer A1): infer R1;
640
+ new (...args: infer A2): infer R2;
641
+ }
642
+ ? (new (...p: A1) => R1) | (new (...p: A2) => R2)
643
+ : ConstructorType extends new (...args: infer A1) => infer R1
644
+ ? new (...p: A1) => R1
645
+ : never;
646
+ /**
647
+ * Get a union of overload variants for a constructor
648
+ * {@linkcode ConstructorType}. Does a check for whether we can do the
649
+ * one-shot 10-overload matcher (which works for ts\>5.3), and if not,
650
+ * falls back to the more complicated utility.
651
+ */
652
+ export type ConstructorOverloadsUnion<ConstructorType> =
653
+ IsNever<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true
654
+ ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType>
655
+ : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
656
+ /**
657
+ * Allows inferring any constructor using the `infer` keyword.
658
+ */
659
+ export type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
660
+ /**
661
+ * A union type of the parameters allowed for any overload
662
+ * of constructor {@linkcode ConstructorType}.
663
+ */
664
+ export type ConstructorOverloadParameters<ConstructorType> =
665
+ ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
666
+ /**
667
+ * Calculates the number of overloads for a given function type.
668
+ */
669
+ export type NumOverloads<FunctionType> = UnionToTuple<OverloadsInfoUnion<FunctionType>>["length"];