bun-types 1.2.20-canary.20250801T140826 → 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,1207 @@
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 { StrictEqualUsingBranding } from "./branding";
196
+ import type {
197
+ ExpectAny,
198
+ ExpectArray,
199
+ ExpectBigInt,
200
+ ExpectBoolean,
201
+ ExpectFunction,
202
+ ExpectNever,
203
+ ExpectNull,
204
+ ExpectNullable,
205
+ ExpectNumber,
206
+ ExpectObject,
207
+ ExpectString,
208
+ ExpectSymbol,
209
+ ExpectUndefined,
210
+ ExpectUnknown,
211
+ ExpectVoid,
212
+ MismatchInfo,
213
+ Scolder,
214
+ } from "./messages";
215
+ import type {
216
+ ConstructorOverloadParameters,
217
+ OverloadParameters,
218
+ OverloadReturnTypes,
219
+ OverloadsNarrowedByParameters,
220
+ } from "./overloads";
221
+ import type {
222
+ AValue,
223
+ DeepPickMatchingProps,
224
+ Extends,
225
+ IsUnion,
226
+ MismatchArgs,
227
+ Not,
228
+ StrictEqualUsingTSInternalIdenticalToOperator,
229
+ } from "./utils";
230
+ export * from "./branding";
231
+ export * from "./messages";
232
+ export * from "./overloads";
233
+ export * from "./utils";
234
+ /**
235
+ * Represents the positive assertion methods available for type checking in the
236
+ * {@linkcode expectTypeOf()} utility.
237
+ */
238
+ export interface PositiveExpectTypeOf<Actual>
239
+ extends BaseExpectTypeOf<
240
+ Actual,
241
+ {
242
+ positive: true;
243
+ branded: false;
244
+ }
245
+ > {
246
+ /**
247
+ * Similar to jest's `expect(...).toMatchObject(...)` but for types.
248
+ * Deeply "picks" the properties of the actual type based on the expected type, then performs a strict check to make sure the types match `Expected`.
249
+ *
250
+ * **Note**: optional properties on the {@linkcode Expected | expected type} are not allowed to be missing on the {@linkcode Actual | actual type}.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * expectTypeOf({ a: 1, b: 1 }).toMatchObjectType<{ a: number }>()
255
+ *
256
+ * expectTypeOf({ a: 1, b: 1 }).not.toMatchObjectType<{ a: number; c?: number }>()
257
+ * ```
258
+ *
259
+ * @param MISMATCH - The mismatch arguments.
260
+ * @returns `true`.
261
+ */
262
+ toMatchObjectType: <
263
+ Expected extends IsUnion<Expected> extends true
264
+ ? "toMatchObject does not support union types"
265
+ : Not<Extends<Expected, Record<string, unknown>>> extends true
266
+ ? "toMatchObject only supports object types"
267
+ : StrictEqualUsingTSInternalIdenticalToOperator<DeepPickMatchingProps<Actual, Expected>, Expected> extends true
268
+ ? unknown
269
+ : MismatchInfo<DeepPickMatchingProps<Actual, Expected>, Expected>,
270
+ >(
271
+ ...MISMATCH: MismatchArgs<
272
+ StrictEqualUsingTSInternalIdenticalToOperator<DeepPickMatchingProps<Actual, Expected>, Expected>,
273
+ true
274
+ >
275
+ ) => true;
276
+ /**
277
+ * Check if your type extends the expected type
278
+ *
279
+ * A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()} that allows for extra properties.
280
+ * This is roughly equivalent to an `extends` constraint in a function type argument.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * expectTypeOf({ a: 1, b: 1 }).toExtend<{ a: number }>()
285
+ *
286
+ * expectTypeOf({ a: 1 }).not.toExtend<{ b: number }>()
287
+ * ```
288
+ *
289
+ * @param MISMATCH - The mismatch arguments.
290
+ * @returns `true`.
291
+ */
292
+ toExtend: <Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(
293
+ ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>
294
+ ) => true;
295
+ toEqualTypeOf: {
296
+ /**
297
+ * Uses TypeScript's internal technique to check for type "identicalness".
298
+ *
299
+ * It will check if the types are fully equal to each other.
300
+ * It will not fail if two objects have different values, but the same type.
301
+ * It will fail however if an object is missing a property.
302
+ *
303
+ * **_Unexpected failure_**? For a more permissive but less performant
304
+ * check that accommodates for equivalent intersection types,
305
+ * use {@linkcode branded | .branded.toEqualTypeOf()}.
306
+ * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
307
+ *
308
+ * @example
309
+ * <caption>Using generic type argument syntax</caption>
310
+ * ```ts
311
+ * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
312
+ *
313
+ * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
314
+ * ```
315
+ *
316
+ * @example
317
+ * <caption>Using inferred type syntax by passing a value</caption>
318
+ * ```ts
319
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
320
+ *
321
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
322
+ * ```
323
+ *
324
+ * @param value - The value to compare against the expected type.
325
+ * @param MISMATCH - The mismatch arguments.
326
+ * @returns `true`.
327
+ */
328
+ <
329
+ Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true
330
+ ? unknown
331
+ : MismatchInfo<Actual, Expected>,
332
+ >(
333
+ value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
334
+ ...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>
335
+ ): true;
336
+ /**
337
+ * Uses TypeScript's internal technique to check for type "identicalness".
338
+ *
339
+ * It will check if the types are fully equal to each other.
340
+ * It will not fail if two objects have different values, but the same type.
341
+ * It will fail however if an object is missing a property.
342
+ *
343
+ * **_Unexpected failure_**? For a more permissive but less performant
344
+ * check that accommodates for equivalent intersection types,
345
+ * use {@linkcode branded | .branded.toEqualTypeOf()}.
346
+ * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
347
+ *
348
+ * @example
349
+ * <caption>Using generic type argument syntax</caption>
350
+ * ```ts
351
+ * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
352
+ *
353
+ * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
354
+ * ```
355
+ *
356
+ * @example
357
+ * <caption>Using inferred type syntax by passing a value</caption>
358
+ * ```ts
359
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
360
+ *
361
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
362
+ * ```
363
+ *
364
+ * @param MISMATCH - The mismatch arguments.
365
+ * @returns `true`.
366
+ */
367
+ <
368
+ Expected extends StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected> extends true
369
+ ? unknown
370
+ : MismatchInfo<Actual, Expected>,
371
+ >(
372
+ ...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, true>
373
+ ): true;
374
+ };
375
+ /**
376
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
377
+ *
378
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
379
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
380
+ */
381
+ toMatchTypeOf: {
382
+ /**
383
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
384
+ *
385
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
386
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
387
+ *
388
+ * A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
389
+ * that allows for extra properties.
390
+ * This is roughly equivalent to an `extends` constraint
391
+ * in a function type argument.
392
+ *
393
+ * @example
394
+ * <caption>Using generic type argument syntax</caption>
395
+ * ```ts
396
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
397
+ * ```
398
+ *
399
+ * @example
400
+ * <caption>Using inferred type syntax by passing a value</caption>
401
+ * ```ts
402
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
403
+ * ```
404
+ *
405
+ * @param value - The value to compare against the expected type.
406
+ * @param MISMATCH - The mismatch arguments.
407
+ * @returns `true`.
408
+ */
409
+ <Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(
410
+ value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
411
+ ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>
412
+ ): true;
413
+ /**
414
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
415
+ *
416
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
417
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
418
+ *
419
+ * A less strict version of {@linkcode toEqualTypeOf | .toEqualTypeOf()}
420
+ * that allows for extra properties.
421
+ * This is roughly equivalent to an `extends` constraint
422
+ * in a function type argument.
423
+ *
424
+ * @example
425
+ * <caption>Using generic type argument syntax</caption>
426
+ * ```ts
427
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
428
+ * ```
429
+ *
430
+ * @example
431
+ * <caption>Using inferred type syntax by passing a value</caption>
432
+ * ```ts
433
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
434
+ * ```
435
+ *
436
+ * @param MISMATCH - The mismatch arguments.
437
+ * @returns `true`.
438
+ */
439
+ <Expected extends Extends<Actual, Expected> extends true ? unknown : MismatchInfo<Actual, Expected>>(
440
+ ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, true>
441
+ ): true;
442
+ };
443
+ /**
444
+ * Checks whether an object has a given property.
445
+ *
446
+ * @example
447
+ * <caption>check that properties exist</caption>
448
+ * ```ts
449
+ * const obj = { a: 1, b: '' }
450
+ *
451
+ * expectTypeOf(obj).toHaveProperty('a')
452
+ *
453
+ * expectTypeOf(obj).not.toHaveProperty('c')
454
+ * ```
455
+ *
456
+ * @param key - The property key to check for.
457
+ * @param MISMATCH - The mismatch arguments.
458
+ * @returns `true`.
459
+ */
460
+ toHaveProperty: <KeyType extends keyof Actual>(
461
+ key: KeyType,
462
+ ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, true>
463
+ ) => KeyType extends keyof Actual ? PositiveExpectTypeOf<Actual[KeyType]> : true;
464
+ /**
465
+ * Inverts the result of the following assertions.
466
+ *
467
+ * @example
468
+ * ```ts
469
+ * expectTypeOf({ a: 1 }).not.toMatchTypeOf({ b: 1 })
470
+ * ```
471
+ */
472
+ not: NegativeExpectTypeOf<Actual>;
473
+ /**
474
+ * Intersection types can cause issues with
475
+ * {@linkcode toEqualTypeOf | .toEqualTypeOf()}:
476
+ * ```ts
477
+ * // ❌ The following line doesn't compile, even though the types are arguably the same.
478
+ * expectTypeOf<{ a: 1 } & { b: 2 }>().toEqualTypeOf<{ a: 1; b: 2 }>()
479
+ * ```
480
+ * This helper works around this problem by using
481
+ * a more permissive but less performant check.
482
+ *
483
+ * __Note__: This comes at a performance cost, and can cause the compiler
484
+ * to 'give up' if used with excessively deep types, so use sparingly.
485
+ *
486
+ * @see {@link https://github.com/mmkal/expect-type/pull/21 | Reference}
487
+ */
488
+ branded: {
489
+ /**
490
+ * Uses TypeScript's internal technique to check for type "identicalness".
491
+ *
492
+ * It will check if the types are fully equal to each other.
493
+ * It will not fail if two objects have different values, but the same type.
494
+ * It will fail however if an object is missing a property.
495
+ *
496
+ * **_Unexpected failure_**? For a more permissive but less performant
497
+ * check that accommodates for equivalent intersection types,
498
+ * use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
499
+ * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
500
+ *
501
+ * @example
502
+ * <caption>Using generic type argument syntax</caption>
503
+ * ```ts
504
+ * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
505
+ *
506
+ * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
507
+ * ```
508
+ *
509
+ * @example
510
+ * <caption>Using inferred type syntax by passing a value</caption>
511
+ * ```ts
512
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
513
+ *
514
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
515
+ * ```
516
+ *
517
+ * @param MISMATCH - The mismatch arguments.
518
+ * @returns `true`.
519
+ */
520
+ toEqualTypeOf: <
521
+ Expected extends StrictEqualUsingBranding<Actual, Expected> extends true
522
+ ? unknown
523
+ : MismatchInfo<Actual, Expected>,
524
+ >(
525
+ ...MISMATCH: MismatchArgs<StrictEqualUsingBranding<Actual, Expected>, true>
526
+ ) => true;
527
+ };
528
+ }
529
+ /**
530
+ * Represents the negative expectation type for the {@linkcode Actual} type.
531
+ */
532
+ export interface NegativeExpectTypeOf<Actual>
533
+ extends BaseExpectTypeOf<
534
+ Actual,
535
+ {
536
+ positive: false;
537
+ }
538
+ > {
539
+ /**
540
+ * Similar to jest's `expect(...).toMatchObject(...)` but for types.
541
+ * Deeply "picks" the properties of the actual type based on the expected type, then performs a strict check to make sure the types match `Expected`.
542
+ *
543
+ * **Note**: optional properties on the {@linkcode Expected | expected type} are not allowed to be missing on the {@linkcode Actual | actual type}.
544
+ *
545
+ * @example
546
+ * ```ts
547
+ * expectTypeOf({ a: 1, b: 1 }).toMatchObjectType<{ a: number }>()
548
+ *
549
+ * expectTypeOf({ a: 1, b: 1 }).not.toMatchObjectType<{ a: number; c?: number }>()
550
+ * ```
551
+ *
552
+ * @param MISMATCH - The mismatch arguments.
553
+ * @returns `true`.
554
+ */
555
+ toMatchObjectType: <Expected>(
556
+ ...MISMATCH: MismatchArgs<
557
+ StrictEqualUsingTSInternalIdenticalToOperator<Pick<Actual, keyof Actual & keyof Expected>, Expected>,
558
+ false
559
+ >
560
+ ) => true;
561
+ /**
562
+ * Check if your type extends the expected type
563
+ *
564
+ * A less strict version of {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()} that allows for extra properties.
565
+ * This is roughly equivalent to an `extends` constraint in a function type argument.
566
+ *
567
+ * @example
568
+ * ```ts
569
+ * expectTypeOf({ a: 1, b: 1 }).toExtend<{ a: number }>()]
570
+ *
571
+ * expectTypeOf({ a: 1 }).not.toExtend<{ b: number }>()
572
+ * ```
573
+ *
574
+ * @param MISMATCH - The mismatch arguments.
575
+ * @returns `true`.
576
+ */
577
+ toExtend<Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
578
+ toEqualTypeOf: {
579
+ /**
580
+ * Uses TypeScript's internal technique to check for type "identicalness".
581
+ *
582
+ * It will check if the types are fully equal to each other.
583
+ * It will not fail if two objects have different values, but the same type.
584
+ * It will fail however if an object is missing a property.
585
+ *
586
+ * **_Unexpected failure_**? For a more permissive but less performant
587
+ * check that accommodates for equivalent intersection types,
588
+ * use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
589
+ * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
590
+ *
591
+ * @example
592
+ * <caption>Using generic type argument syntax</caption>
593
+ * ```ts
594
+ * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
595
+ *
596
+ * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
597
+ * ```
598
+ *
599
+ * @example
600
+ * <caption>Using inferred type syntax by passing a value</caption>
601
+ * ```ts
602
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
603
+ *
604
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
605
+ * ```
606
+ *
607
+ * @param value - The value to compare against the expected type.
608
+ * @param MISMATCH - The mismatch arguments.
609
+ * @returns `true`.
610
+ */
611
+ <Expected>(
612
+ value: Expected & AValue,
613
+ ...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>
614
+ ): true;
615
+ /**
616
+ * Uses TypeScript's internal technique to check for type "identicalness".
617
+ *
618
+ * It will check if the types are fully equal to each other.
619
+ * It will not fail if two objects have different values, but the same type.
620
+ * It will fail however if an object is missing a property.
621
+ *
622
+ * **_Unexpected failure_**? For a more permissive but less performant
623
+ * check that accommodates for equivalent intersection types,
624
+ * use {@linkcode PositiveExpectTypeOf.branded | .branded.toEqualTypeOf()}.
625
+ * @see {@link https://github.com/mmkal/expect-type#why-is-my-assertion-failing | The documentation for details}.
626
+ *
627
+ * @example
628
+ * <caption>Using generic type argument syntax</caption>
629
+ * ```ts
630
+ * expectTypeOf({ a: 1 }).toEqualTypeOf<{ a: number }>()
631
+ *
632
+ * expectTypeOf({ a: 1, b: 1 }).not.toEqualTypeOf<{ a: number }>()
633
+ * ```
634
+ *
635
+ * @example
636
+ * <caption>Using inferred type syntax by passing a value</caption>
637
+ * ```ts
638
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 1 })
639
+ *
640
+ * expectTypeOf({ a: 1 }).toEqualTypeOf({ a: 2 })
641
+ * ```
642
+ *
643
+ * @param MISMATCH - The mismatch arguments.
644
+ * @returns `true`.
645
+ */
646
+ <Expected>(...MISMATCH: MismatchArgs<StrictEqualUsingTSInternalIdenticalToOperator<Actual, Expected>, false>): true;
647
+ };
648
+ /**
649
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
650
+ *
651
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
652
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
653
+ */
654
+ toMatchTypeOf: {
655
+ /**
656
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
657
+ *
658
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
659
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
660
+ *
661
+ * A less strict version of
662
+ * {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
663
+ * that allows for extra properties.
664
+ * This is roughly equivalent to an `extends` constraint
665
+ * in a function type argument.
666
+ *
667
+ * @example
668
+ * <caption>Using generic type argument syntax</caption>
669
+ * ```ts
670
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
671
+ * ```
672
+ *
673
+ * @example
674
+ * <caption>Using inferred type syntax by passing a value</caption>
675
+ * ```ts
676
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
677
+ * ```
678
+ *
679
+ * @param value - The value to compare against the expected type.
680
+ * @param MISMATCH - The mismatch arguments.
681
+ * @returns `true`.
682
+ */
683
+ <Expected>(
684
+ value: Expected & AValue, // reason for `& AValue`: make sure this is only the selected overload when the end-user passes a value for an inferred typearg. The `Mismatch` type does match `AValue`.
685
+ ...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>
686
+ ): true;
687
+ /**
688
+ * @deprecated Use either {@linkcode toMatchObjectType} or {@linkcode toExtend} instead
689
+ *
690
+ * - Use {@linkcode toMatchObjectType} to perform a strict check on a subset of your type's keys
691
+ * - Use {@linkcode toExtend} to check if your type extends the expected type
692
+ *
693
+ * A less strict version of
694
+ * {@linkcode PositiveExpectTypeOf.toEqualTypeOf | .toEqualTypeOf()}
695
+ * that allows for extra properties.
696
+ * This is roughly equivalent to an `extends` constraint
697
+ * in a function type argument.
698
+ *
699
+ * @example
700
+ * <caption>Using generic type argument syntax</caption>
701
+ * ```ts
702
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf<{ a: number }>()
703
+ * ```
704
+ *
705
+ * @example
706
+ * <caption>Using inferred type syntax by passing a value</caption>
707
+ * ```ts
708
+ * expectTypeOf({ a: 1, b: 1 }).toMatchTypeOf({ a: 2 })
709
+ * ```
710
+ *
711
+ * @param MISMATCH - The mismatch arguments.
712
+ * @returns `true`.
713
+ */
714
+ <Expected>(...MISMATCH: MismatchArgs<Extends<Actual, Expected>, false>): true;
715
+ };
716
+ /**
717
+ * Checks whether an object has a given property.
718
+ *
719
+ * @example
720
+ * <caption>check that properties exist</caption>
721
+ * ```ts
722
+ * const obj = { a: 1, b: '' }
723
+ *
724
+ * expectTypeOf(obj).toHaveProperty('a')
725
+ *
726
+ * expectTypeOf(obj).not.toHaveProperty('c')
727
+ * ```
728
+ *
729
+ * @param key - The property key to check for.
730
+ * @param MISMATCH - The mismatch arguments.
731
+ * @returns `true`.
732
+ */
733
+ toHaveProperty: <KeyType extends string | number | symbol>(
734
+ key: KeyType,
735
+ ...MISMATCH: MismatchArgs<Extends<KeyType, keyof Actual>, false>
736
+ ) => true;
737
+ }
738
+ /**
739
+ * Represents a conditional type that selects either
740
+ * {@linkcode PositiveExpectTypeOf} or {@linkcode NegativeExpectTypeOf} based
741
+ * on the value of the `positive` property in the {@linkcode Options} type.
742
+ */
743
+ export type ExpectTypeOf<
744
+ Actual,
745
+ Options extends {
746
+ positive: boolean;
747
+ },
748
+ > = Options["positive"] extends true ? PositiveExpectTypeOf<Actual> : NegativeExpectTypeOf<Actual>;
749
+ /**
750
+ * Represents the base interface for the
751
+ * {@linkcode expectTypeOf()} function.
752
+ * Provides a set of assertion methods to perform type checks on a value.
753
+ */
754
+ export interface BaseExpectTypeOf<
755
+ Actual,
756
+ Options extends {
757
+ positive: boolean;
758
+ },
759
+ > {
760
+ /**
761
+ * Checks whether the type of the value is `any`.
762
+ */
763
+ toBeAny: Scolder<ExpectAny<Actual>, Options>;
764
+ /**
765
+ * Checks whether the type of the value is `unknown`.
766
+ */
767
+ toBeUnknown: Scolder<ExpectUnknown<Actual>, Options>;
768
+ /**
769
+ * Checks whether the type of the value is `never`.
770
+ */
771
+ toBeNever: Scolder<ExpectNever<Actual>, Options>;
772
+ /**
773
+ * Checks whether the type of the value is `function`.
774
+ */
775
+ toBeFunction: Scolder<ExpectFunction<Actual>, Options>;
776
+ /**
777
+ * Checks whether the type of the value is `object`.
778
+ */
779
+ toBeObject: Scolder<ExpectObject<Actual>, Options>;
780
+ /**
781
+ * Checks whether the type of the value is an {@linkcode Array}.
782
+ */
783
+ toBeArray: Scolder<ExpectArray<Actual>, Options>;
784
+ /**
785
+ * Checks whether the type of the value is `number`.
786
+ */
787
+ toBeNumber: Scolder<ExpectNumber<Actual>, Options>;
788
+ /**
789
+ * Checks whether the type of the value is `string`.
790
+ */
791
+ toBeString: Scolder<ExpectString<Actual>, Options>;
792
+ /**
793
+ * Checks whether the type of the value is `boolean`.
794
+ */
795
+ toBeBoolean: Scolder<ExpectBoolean<Actual>, Options>;
796
+ /**
797
+ * Checks whether the type of the value is `void`.
798
+ */
799
+ toBeVoid: Scolder<ExpectVoid<Actual>, Options>;
800
+ /**
801
+ * Checks whether the type of the value is `symbol`.
802
+ */
803
+ toBeSymbol: Scolder<ExpectSymbol<Actual>, Options>;
804
+ /**
805
+ * Checks whether the type of the value is `null`.
806
+ */
807
+ toBeNull: Scolder<ExpectNull<Actual>, Options>;
808
+ /**
809
+ * Checks whether the type of the value is `undefined`.
810
+ */
811
+ toBeUndefined: Scolder<ExpectUndefined<Actual>, Options>;
812
+ /**
813
+ * Checks whether the type of the value is `null` or `undefined`.
814
+ */
815
+ toBeNullable: Scolder<ExpectNullable<Actual>, Options>;
816
+ /**
817
+ * Transform that type of the value via a callback.
818
+ *
819
+ * @param fn - A callback that transforms the input value. Note that this function is not actually called - it's only used for type inference.
820
+ * @returns A new type which can be used for further assertions.
821
+ */
822
+ map: <T>(fn: (value: Actual) => T) => ExpectTypeOf<T, Options>;
823
+ /**
824
+ * Checks whether the type of the value is **`bigint`**.
825
+ *
826
+ * @example
827
+ * <caption>#### Distinguish between **`number`** and **`bigint`**</caption>
828
+ *
829
+ * ```ts
830
+ * import { expectTypeOf } from 'expect-type'
831
+ *
832
+ * const aVeryBigInteger = 10n ** 100n
833
+ *
834
+ * expectTypeOf(aVeryBigInteger).not.toBeNumber()
835
+ *
836
+ * expectTypeOf(aVeryBigInteger).toBeBigInt()
837
+ * ```
838
+ *
839
+ * @since 1.1.0
840
+ */
841
+ toBeBigInt: Scolder<ExpectBigInt<Actual>, Options>;
842
+ /**
843
+ * Checks whether a function is callable with the given parameters.
844
+ *
845
+ * __Note__: You cannot negate this assertion with
846
+ * {@linkcode PositiveExpectTypeOf.not | .not}, you need to use
847
+ * `ts-expect-error` instead.
848
+ *
849
+ * @example
850
+ * ```ts
851
+ * const f = (a: number) => [a, a]
852
+ *
853
+ * expectTypeOf(f).toBeCallableWith(1)
854
+ * ```
855
+ *
856
+ * __Known Limitation__: This assertion will likely fail if you try to use it
857
+ * with a generic function or an overload.
858
+ * @see {@link https://github.com/mmkal/expect-type/issues/50 | This issue} for an example and a workaround.
859
+ *
860
+ * @param args - The arguments to check for callability.
861
+ * @returns `true`.
862
+ */
863
+ toBeCallableWith: Options["positive"] extends true
864
+ ? <Args extends OverloadParameters<Actual>>(
865
+ ...args: Args
866
+ ) => ExpectTypeOf<OverloadsNarrowedByParameters<Actual, Args>, Options>
867
+ : never;
868
+ /**
869
+ * Checks whether a class is constructible with the given parameters.
870
+ *
871
+ * @example
872
+ * ```ts
873
+ * expectTypeOf(Date).toBeConstructibleWith('1970')
874
+ *
875
+ * expectTypeOf(Date).toBeConstructibleWith(0)
876
+ *
877
+ * expectTypeOf(Date).toBeConstructibleWith(new Date())
878
+ *
879
+ * expectTypeOf(Date).toBeConstructibleWith()
880
+ * ```
881
+ *
882
+ * @param args - The arguments to check for constructibility.
883
+ * @returns `true`.
884
+ */
885
+ toBeConstructibleWith: Options["positive"] extends true
886
+ ? <Args extends ConstructorOverloadParameters<Actual>>(...args: Args) => true
887
+ : never;
888
+ /**
889
+ * Equivalent to the {@linkcode Extract} utility type.
890
+ * Helps narrow down complex union types.
891
+ *
892
+ * @example
893
+ * ```ts
894
+ * type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
895
+ *
896
+ * interface CSSProperties {
897
+ * margin?: string
898
+ * padding?: string
899
+ * }
900
+ *
901
+ * function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
902
+ * return {}
903
+ * }
904
+ *
905
+ * const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
906
+ *
907
+ * expectTypeOf(getResponsiveProp(cssProperties))
908
+ * .extract<{ xs?: any }>() // extracts the last type from a union
909
+ * .toEqualTypeOf<{
910
+ * xs?: CSSProperties
911
+ * sm?: CSSProperties
912
+ * md?: CSSProperties
913
+ * }>()
914
+ *
915
+ * expectTypeOf(getResponsiveProp(cssProperties))
916
+ * .extract<unknown[]>() // extracts an array from a union
917
+ * .toEqualTypeOf<CSSProperties[]>()
918
+ * ```
919
+ *
920
+ * __Note__: If no type is found in the union, it will return `never`.
921
+ *
922
+ * @param v - The type to extract from the union.
923
+ * @returns The type after extracting the type from the union.
924
+ */
925
+ extract: <V>(v?: V) => ExpectTypeOf<Extract<Actual, V>, Options>;
926
+ /**
927
+ * Equivalent to the {@linkcode Exclude} utility type.
928
+ * Removes types from a union.
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * type ResponsiveProp<T> = T | T[] | { xs?: T; sm?: T; md?: T }
933
+ *
934
+ * interface CSSProperties {
935
+ * margin?: string
936
+ * padding?: string
937
+ * }
938
+ *
939
+ * function getResponsiveProp<T>(_props: T): ResponsiveProp<T> {
940
+ * return {}
941
+ * }
942
+ *
943
+ * const cssProperties: CSSProperties = { margin: '1px', padding: '2px' }
944
+ *
945
+ * expectTypeOf(getResponsiveProp(cssProperties))
946
+ * .exclude<unknown[]>()
947
+ * .exclude<{ xs?: unknown }>() // or just `.exclude<unknown[] | { xs?: unknown }>()`
948
+ * .toEqualTypeOf<CSSProperties>()
949
+ * ```
950
+ */
951
+ exclude: <V>(v?: V) => ExpectTypeOf<Exclude<Actual, V>, Options>;
952
+ /**
953
+ * Equivalent to the {@linkcode Pick} utility type.
954
+ * Helps select a subset of properties from an object type.
955
+ *
956
+ * @example
957
+ * ```ts
958
+ * interface Person {
959
+ * name: string
960
+ * age: number
961
+ * }
962
+ *
963
+ * expectTypeOf<Person>()
964
+ * .pick<'name'>()
965
+ * .toEqualTypeOf<{ name: string }>()
966
+ * ```
967
+ *
968
+ * @param keyToPick - The property key to pick.
969
+ * @returns The type after picking the property.
970
+ */
971
+ pick: <KeyToPick extends keyof Actual>(keyToPick?: KeyToPick) => ExpectTypeOf<Pick<Actual, KeyToPick>, Options>;
972
+ /**
973
+ * Equivalent to the {@linkcode Omit} utility type.
974
+ * Helps remove a subset of properties from an object type.
975
+ *
976
+ * @example
977
+ * ```ts
978
+ * interface Person {
979
+ * name: string
980
+ * age: number
981
+ * }
982
+ *
983
+ * expectTypeOf<Person>().omit<'name'>().toEqualTypeOf<{ age: number }>()
984
+ * ```
985
+ *
986
+ * @param keyToOmit - The property key to omit.
987
+ * @returns The type after omitting the property.
988
+ */
989
+ omit: <KeyToOmit extends keyof Actual | (PropertyKey & Record<never, never>)>(
990
+ keyToOmit?: KeyToOmit,
991
+ ) => ExpectTypeOf<Omit<Actual, KeyToOmit>, Options>;
992
+ /**
993
+ * Extracts a certain function argument with `.parameter(number)` call to
994
+ * perform other assertions on it.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * function foo(a: number, b: string) {
999
+ * return [a, b]
1000
+ * }
1001
+ *
1002
+ * expectTypeOf(foo).parameter(0).toBeNumber()
1003
+ *
1004
+ * expectTypeOf(foo).parameter(1).toBeString()
1005
+ * ```
1006
+ *
1007
+ * @param index - The index of the parameter to extract.
1008
+ * @returns The extracted parameter type.
1009
+ */
1010
+ parameter: <Index extends number>(index: Index) => ExpectTypeOf<OverloadParameters<Actual>[Index], Options>;
1011
+ /**
1012
+ * Equivalent to the {@linkcode Parameters} utility type.
1013
+ * Extracts function parameters to perform assertions on its value.
1014
+ * Parameters are returned as an array.
1015
+ *
1016
+ * @example
1017
+ * ```ts
1018
+ * function noParam() {}
1019
+ *
1020
+ * function hasParam(s: string) {}
1021
+ *
1022
+ * expectTypeOf(noParam).parameters.toEqualTypeOf<[]>()
1023
+ *
1024
+ * expectTypeOf(hasParam).parameters.toEqualTypeOf<[string]>()
1025
+ * ```
1026
+ */
1027
+ parameters: ExpectTypeOf<OverloadParameters<Actual>, Options>;
1028
+ /**
1029
+ * Equivalent to the {@linkcode ConstructorParameters} utility type.
1030
+ * Extracts constructor parameters as an array of values and
1031
+ * perform assertions on them with this method.
1032
+ *
1033
+ * For overloaded constructors it will return a union of all possible parameter-tuples.
1034
+ *
1035
+ * @example
1036
+ * ```ts
1037
+ * expectTypeOf(Date).constructorParameters.toEqualTypeOf<
1038
+ * [] | [string | number | Date]
1039
+ * >()
1040
+ * ```
1041
+ */
1042
+ constructorParameters: ExpectTypeOf<ConstructorOverloadParameters<Actual>, Options>;
1043
+ /**
1044
+ * Equivalent to the {@linkcode ThisParameterType} utility type.
1045
+ * Extracts the `this` parameter of a function to
1046
+ * perform assertions on its value.
1047
+ *
1048
+ * @example
1049
+ * ```ts
1050
+ * function greet(this: { name: string }, message: string) {
1051
+ * return `Hello ${this.name}, here's your message: ${message}`
1052
+ * }
1053
+ *
1054
+ * expectTypeOf(greet).thisParameter.toEqualTypeOf<{ name: string }>()
1055
+ * ```
1056
+ */
1057
+ thisParameter: ExpectTypeOf<ThisParameterType<Actual>, Options>;
1058
+ /**
1059
+ * Equivalent to the {@linkcode InstanceType} utility type.
1060
+ * Extracts the instance type of a class to perform assertions on.
1061
+ *
1062
+ * @example
1063
+ * ```ts
1064
+ * expectTypeOf(Date).instance.toHaveProperty('toISOString')
1065
+ * ```
1066
+ */
1067
+ instance: Actual extends new (...args: any[]) => infer I ? ExpectTypeOf<I, Options> : never;
1068
+ /**
1069
+ * Equivalent to the {@linkcode ReturnType} utility type.
1070
+ * Extracts the return type of a function.
1071
+ *
1072
+ * @example
1073
+ * ```ts
1074
+ * expectTypeOf(() => {}).returns.toBeVoid()
1075
+ *
1076
+ * expectTypeOf((a: number) => [a, a]).returns.toEqualTypeOf([1, 2])
1077
+ * ```
1078
+ */
1079
+ returns: Actual extends Function ? ExpectTypeOf<OverloadReturnTypes<Actual>, Options> : never;
1080
+ /**
1081
+ * Extracts resolved value of a Promise,
1082
+ * so you can perform other assertions on it.
1083
+ *
1084
+ * @example
1085
+ * ```ts
1086
+ * async function asyncFunc() {
1087
+ * return 123
1088
+ * }
1089
+ *
1090
+ * expectTypeOf(asyncFunc).returns.resolves.toBeNumber()
1091
+ *
1092
+ * expectTypeOf(Promise.resolve('string')).resolves.toBeString()
1093
+ * ```
1094
+ *
1095
+ * Type Equivalent:
1096
+ * ```ts
1097
+ * type Resolves<PromiseType> = PromiseType extends PromiseLike<infer ResolvedType>
1098
+ * ? ResolvedType
1099
+ * : never
1100
+ * ```
1101
+ */
1102
+ resolves: Actual extends PromiseLike<infer ResolvedType> ? ExpectTypeOf<ResolvedType, Options> : never;
1103
+ /**
1104
+ * Extracts array item type to perform assertions on.
1105
+ *
1106
+ * @example
1107
+ * ```ts
1108
+ * expectTypeOf([1, 2, 3]).items.toEqualTypeOf<number>()
1109
+ *
1110
+ * expectTypeOf([1, 2, 3]).items.not.toEqualTypeOf<string>()
1111
+ * ```
1112
+ *
1113
+ * __Type Equivalent__:
1114
+ * ```ts
1115
+ * type Items<ArrayType> = ArrayType extends ArrayLike<infer ItemType>
1116
+ * ? ItemType
1117
+ * : never
1118
+ * ```
1119
+ */
1120
+ items: Actual extends ArrayLike<infer ItemType> ? ExpectTypeOf<ItemType, Options> : never;
1121
+ /**
1122
+ * Extracts the type guarded by a function to perform assertions on.
1123
+ *
1124
+ * @example
1125
+ * ```ts
1126
+ * function isString(v: any): v is string {
1127
+ * return typeof v === 'string'
1128
+ * }
1129
+ *
1130
+ * expectTypeOf(isString).guards.toBeString()
1131
+ * ```
1132
+ */
1133
+ guards: Actual extends (v: any, ...args: any[]) => v is infer T ? ExpectTypeOf<T, Options> : never;
1134
+ /**
1135
+ * Extracts the type asserted by a function to perform assertions on.
1136
+ *
1137
+ * @example
1138
+ * ```ts
1139
+ * function assertNumber(v: any): asserts v is number {
1140
+ * if (typeof v !== 'number')
1141
+ * throw new TypeError('Nope !')
1142
+ * }
1143
+ *
1144
+ * expectTypeOf(assertNumber).asserts.toBeNumber()
1145
+ * ```
1146
+ */
1147
+ asserts: Actual extends (v: any, ...args: any[]) => asserts v is infer T
1148
+ ? unknown extends T
1149
+ ? never
1150
+ : ExpectTypeOf<T, Options>
1151
+ : never;
1152
+ }
1153
+ /**
1154
+ * Represents a function that allows asserting the expected type of a value.
1155
+ */
1156
+ export type _ExpectTypeOf = {
1157
+ /**
1158
+ * Asserts the expected type of a value.
1159
+ *
1160
+ * @param actual - The actual value being asserted.
1161
+ * @returns An object representing the expected type assertion.
1162
+ */
1163
+ <Actual>(actual: Actual): ExpectTypeOf<
1164
+ Actual,
1165
+ {
1166
+ positive: true;
1167
+ branded: false;
1168
+ }
1169
+ >;
1170
+ /**
1171
+ * Asserts the expected type of a value without providing an actual value.
1172
+ *
1173
+ * @returns An object representing the expected type assertion.
1174
+ */
1175
+ <Actual>(): ExpectTypeOf<
1176
+ Actual,
1177
+ {
1178
+ positive: true;
1179
+ branded: false;
1180
+ }
1181
+ >;
1182
+ };
1183
+ /**
1184
+ * Similar to Jest's `expect`, but with type-awareness.
1185
+ * Gives you access to a number of type-matchers that let you make assertions about the
1186
+ * form of a reference or generic type parameter.
1187
+ *
1188
+ * @example
1189
+ * ```ts
1190
+ * import { foo, bar } from '../foo'
1191
+ * import { expectTypeOf } from 'expect-type'
1192
+ *
1193
+ * test('foo types', () => {
1194
+ * // make sure `foo` has type { a: number }
1195
+ * expectTypeOf(foo).toMatchTypeOf({ a: 1 })
1196
+ * expectTypeOf(foo).toHaveProperty('a').toBeNumber()
1197
+ *
1198
+ * // make sure `bar` is a function taking a string:
1199
+ * expectTypeOf(bar).parameter(0).toBeString()
1200
+ * expectTypeOf(bar).returns.not.toBeAny()
1201
+ * })
1202
+ * ```
1203
+ *
1204
+ * @description
1205
+ * See the [full docs](https://npmjs.com/package/expect-type#documentation) for lots more examples.
1206
+ */
1207
+ export declare const expectTypeOf: _ExpectTypeOf;