@visulima/package 5.0.12 → 5.0.13

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,2856 @@
1
+ import { WriteJsonOptions } from '@visulima/fs';
2
+ import { InstallPackageOptions } from '@antfu/install-pkg';
3
+ import { Package } from 'normalize-package-data';
4
+ import { a as JsonValue, J as JsonObject } from "./json-value.d-AIF0oxA6.js";
5
+ /**
6
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
7
+
8
+ @category Type
9
+ */
10
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
11
+ /**
12
+ Matches any digit as a string ('0'-'9').
13
+
14
+ @example
15
+ ```
16
+ import type {DigitCharacter} from 'type-fest';
17
+
18
+ const a: DigitCharacter = '0'; // Valid
19
+ // @ts-expect-error
20
+ const b: DigitCharacter = 0; // Invalid
21
+ ```
22
+
23
+ @category Type
24
+ */
25
+ type DigitCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
26
+ /**
27
+ Returns a boolean for whether the given type is `any`.
28
+
29
+ @link https://stackoverflow.com/a/49928360/1490091
30
+
31
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
32
+
33
+ @example
34
+ ```
35
+ import type {IsAny} from 'type-fest';
36
+
37
+ const typedObject = {a: 1, b: 2} as const;
38
+ const anyObject: any = {a: 1, b: 2};
39
+
40
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
41
+ return object[key];
42
+ }
43
+
44
+ const typedA = get(typedObject, 'a');
45
+ //=> 1
46
+
47
+ const anyA = get(anyObject, 'a');
48
+ //=> any
49
+ ```
50
+
51
+ @category Type Guard
52
+ @category Utilities
53
+ */
54
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
55
+ /**
56
+ Returns a boolean for whether the given key is an optional key of type.
57
+
58
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
59
+
60
+ @example
61
+ ```
62
+ import type {IsOptionalKeyOf} from 'type-fest';
63
+
64
+ type User = {
65
+ name: string;
66
+ surname: string;
67
+
68
+ luckyNumber?: number;
69
+ };
70
+
71
+ type Admin = {
72
+ name: string;
73
+ surname?: string;
74
+ };
75
+
76
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
77
+ //=> true
78
+
79
+ type T2 = IsOptionalKeyOf<User, 'name'>;
80
+ //=> false
81
+
82
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
83
+ //=> boolean
84
+
85
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
86
+ //=> false
87
+
88
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
89
+ //=> boolean
90
+ ```
91
+
92
+ @category Type Guard
93
+ @category Utilities
94
+ */
95
+ type IsOptionalKeyOf<Type extends object, Key extends keyof Type> = IsAny<Type | Key> extends true ? never : Key extends keyof Type ? Type extends Record<Key, Type[Key]> ? false : true : false;
96
+ /**
97
+ Extract all optional keys from the given type.
98
+
99
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
100
+
101
+ @example
102
+ ```
103
+ import type {OptionalKeysOf, Except} from 'type-fest';
104
+
105
+ type User = {
106
+ name: string;
107
+ surname: string;
108
+
109
+ luckyNumber?: number;
110
+ };
111
+
112
+ const REMOVE_FIELD = Symbol('remove field symbol');
113
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
114
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
115
+ };
116
+
117
+ const update1: UpdateOperation<User> = {
118
+ name: 'Alice',
119
+ };
120
+
121
+ const update2: UpdateOperation<User> = {
122
+ name: 'Bob',
123
+ luckyNumber: REMOVE_FIELD,
124
+ };
125
+ ```
126
+
127
+ @category Utilities
128
+ */
129
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
130
+ ? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never; }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
131
+ : never; // Should never happen
132
+ /**
133
+ Extract all required keys from the given type.
134
+
135
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
136
+
137
+ @example
138
+ ```
139
+ import type {RequiredKeysOf} from 'type-fest';
140
+
141
+ declare function createValidation<
142
+ Entity extends object,
143
+ Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
144
+ >(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
145
+
146
+ type User = {
147
+ name: string;
148
+ surname: string;
149
+ luckyNumber?: number;
150
+ };
151
+
152
+ const validator1 = createValidation<User>('name', value => value.length < 25);
153
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
154
+
155
+ // @ts-expect-error
156
+ const validator3 = createValidation<User>('luckyNumber', value => value > 0);
157
+ // Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
158
+ ```
159
+
160
+ @category Utilities
161
+ */
162
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
163
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never; // Should never happen
164
+ /**
165
+ Returns a boolean for whether the given type is `never`.
166
+
167
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
168
+ @link https://stackoverflow.com/a/53984913/10292952
169
+ @link https://www.zhenghao.io/posts/ts-never
170
+
171
+ Useful in type utilities, such as checking if something does not occur.
172
+
173
+ @example
174
+ ```
175
+ import type {IsNever, And} from 'type-fest';
176
+
177
+ type A = IsNever<never>;
178
+ //=> true
179
+
180
+ type B = IsNever<any>;
181
+ //=> false
182
+
183
+ type C = IsNever<unknown>;
184
+ //=> false
185
+
186
+ type D = IsNever<never[]>;
187
+ //=> false
188
+
189
+ type E = IsNever<object>;
190
+ //=> false
191
+
192
+ type F = IsNever<string>;
193
+ //=> false
194
+ ```
195
+
196
+ @example
197
+ ```
198
+ import type {IsNever} from 'type-fest';
199
+
200
+ type IsTrue<T> = T extends true ? true : false;
201
+
202
+ // When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
203
+ type A = IsTrue<never>;
204
+ //=> never
205
+
206
+ // If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
207
+ type IsTrueFixed<T> =
208
+ IsNever<T> extends true ? false : T extends true ? true : false;
209
+
210
+ type B = IsTrueFixed<never>;
211
+ //=> false
212
+ ```
213
+
214
+ @category Type Guard
215
+ @category Utilities
216
+ */
217
+ type IsNever<T> = [T] extends [never] ? true : false;
218
+ /**
219
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
220
+
221
+ Use-cases:
222
+ - You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
223
+
224
+ Note:
225
+ - Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
226
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
227
+
228
+ @example
229
+ ```
230
+ import type {If} from 'type-fest';
231
+
232
+ type A = If<true, 'yes', 'no'>;
233
+ //=> 'yes'
234
+
235
+ type B = If<false, 'yes', 'no'>;
236
+ //=> 'no'
237
+
238
+ type C = If<boolean, 'yes', 'no'>;
239
+ //=> 'yes' | 'no'
240
+
241
+ type D = If<any, 'yes', 'no'>;
242
+ //=> 'yes' | 'no'
243
+
244
+ type E = If<never, 'yes', 'no'>;
245
+ //=> 'no'
246
+ ```
247
+
248
+ @example
249
+ ```
250
+ import type {If, IsAny, IsNever} from 'type-fest';
251
+
252
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
253
+ //=> 'not any'
254
+
255
+ type B = If<IsNever<never>, 'is never', 'not never'>;
256
+ //=> 'is never'
257
+ ```
258
+
259
+ @example
260
+ ```
261
+ import type {If, IsEqual} from 'type-fest';
262
+
263
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
264
+
265
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
266
+ //=> 'equal'
267
+
268
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
269
+ //=> 'not equal'
270
+ ```
271
+
272
+ Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
273
+
274
+ @example
275
+ ```
276
+ import type {If, IsEqual, StringRepeat} from 'type-fest';
277
+
278
+ type HundredZeroes = StringRepeat<'0', 100>;
279
+
280
+ // The following implementation is not tail recursive
281
+ type Includes<S extends string, Char extends string> =
282
+ S extends `${infer First}${infer Rest}`
283
+ ? If<IsEqual<First, Char>,
284
+ 'found',
285
+ Includes<Rest, Char>>
286
+ : 'not found';
287
+
288
+ // Hence, instantiations with long strings will fail
289
+ // @ts-expect-error
290
+ type Fails = Includes<HundredZeroes, '1'>;
291
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292
+ // Error: Type instantiation is excessively deep and possibly infinite.
293
+
294
+ // However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
295
+ type IncludesWithoutIf<S extends string, Char extends string> =
296
+ S extends `${infer First}${infer Rest}`
297
+ ? IsEqual<First, Char> extends true
298
+ ? 'found'
299
+ : IncludesWithoutIf<Rest, Char>
300
+ : 'not found';
301
+
302
+ // Now, instantiations with long strings will work
303
+ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
304
+ //=> 'not found'
305
+ ```
306
+
307
+ @category Type Guard
308
+ @category Utilities
309
+ */
310
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
311
+ /**
312
+ Represents an array with `unknown` value.
313
+
314
+ Use case: You want a type that all arrays can be assigned to, but you don't care about the value.
315
+
316
+ @example
317
+ ```
318
+ import type {UnknownArray} from 'type-fest';
319
+
320
+ type IsArray<T> = T extends UnknownArray ? true : false;
321
+
322
+ type A = IsArray<['foo']>;
323
+ //=> true
324
+
325
+ type B = IsArray<readonly number[]>;
326
+ //=> true
327
+
328
+ type C = IsArray<string>;
329
+ //=> false
330
+ ```
331
+
332
+ @category Type
333
+ @category Array
334
+ */
335
+ type UnknownArray = readonly unknown[];
336
+ /**
337
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
338
+ */
339
+ type BuiltIns = Primitive | void | Date | RegExp;
340
+ /**
341
+ Matches non-recursive types.
342
+ */
343
+ type NonRecursiveType = BuiltIns | Function | (new (...arguments_: any[]) => unknown) | Promise<unknown>;
344
+ /**
345
+ Matches maps, sets, or arrays.
346
+ */
347
+ type MapsSetsOrArrays = ReadonlyMap<unknown, unknown> | WeakMap<WeakKey, unknown> | ReadonlySet<unknown> | WeakSet<WeakKey> | UnknownArray;
348
+ /**
349
+ Returns a boolean for whether A is false.
350
+
351
+ @example
352
+ ```
353
+ type A = Not<true>;
354
+ //=> false
355
+
356
+ type B = Not<false>;
357
+ //=> true
358
+ ```
359
+ */
360
+ type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
361
+ /**
362
+ An if-else-like type that resolves depending on whether the given type is `any` or `never`.
363
+
364
+ @example
365
+ ```
366
+ // When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
367
+ type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
368
+ //=> 'VALID'
369
+
370
+ // When `T` is `any` => Returns `IfAny` branch
371
+ type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
372
+ //=> 'IS_ANY'
373
+
374
+ // When `T` is `never` => Returns `IfNever` branch
375
+ type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
376
+ //=> 'IS_NEVER'
377
+ ```
378
+
379
+ Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
380
+
381
+ @example
382
+ ```ts
383
+ import type {StringRepeat} from 'type-fest';
384
+
385
+ type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
386
+
387
+ // The following implementation is not tail recursive
388
+ type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
389
+
390
+ // Hence, instantiations with long strings will fail
391
+ // @ts-expect-error
392
+ type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
393
+ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
394
+ // Error: Type instantiation is excessively deep and possibly infinite.
395
+
396
+ // To fix this, move the recursion into a helper type
397
+ type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
398
+
399
+ type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
400
+
401
+ type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
402
+ //=> ''
403
+ ```
404
+ */
405
+ type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever<T>, IfNever, IfNotAnyOrNever>>;
406
+ /**
407
+ Indicates the value of `exactOptionalPropertyTypes` compiler option.
408
+ */
409
+ type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?] ? false : true;
410
+ /**
411
+ Transforms a tuple type by replacing it's rest element with a single element that has the same type as the rest element, while keeping all the non-rest elements intact.
412
+
413
+ @example
414
+ ```
415
+ type A = CollapseRestElement<[string, string, ...number[]]>;
416
+ //=> [string, string, number]
417
+
418
+ type B = CollapseRestElement<[...string[], number, number]>;
419
+ //=> [string, number, number]
420
+
421
+ type C = CollapseRestElement<[string, string, ...Array<number | bigint>]>;
422
+ //=> [string, string, number | bigint]
423
+
424
+ type D = CollapseRestElement<[string, number]>;
425
+ //=> [string, number]
426
+ ```
427
+
428
+ Note: Optional modifiers (`?`) are removed from elements unless the `exactOptionalPropertyTypes` compiler option is disabled. When disabled, there's an additional `| undefined` for optional elements.
429
+
430
+ @example
431
+ ```
432
+ // `exactOptionalPropertyTypes` enabled
433
+ type A = CollapseRestElement<[string?, string?, ...number[]]>;
434
+ //=> [string, string, number]
435
+
436
+ // `exactOptionalPropertyTypes` disabled
437
+ type B = CollapseRestElement<[string?, string?, ...number[]]>;
438
+ //=> [string | undefined, string | undefined, number]
439
+ ```
440
+ */
441
+ type CollapseRestElement<TArray extends UnknownArray> = IfNotAnyOrNever<TArray, _CollapseRestElement<TArray>>;
442
+ type _CollapseRestElement<TArray extends UnknownArray, ForwardAccumulator extends UnknownArray = [], BackwardAccumulator extends UnknownArray = []> = TArray extends UnknownArray // For distributing `TArray`
443
+ ? keyof TArray & `${number}` extends never ?
444
+ // Enters this branch, if `TArray` is empty (e.g., []),
445
+ // or `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
446
+ TArray extends readonly [...infer Rest, infer Last] ? _CollapseRestElement<Rest, ForwardAccumulator, [Last, ...BackwardAccumulator]> // Accumulate elements that are present after the rest element.
447
+ : TArray extends readonly [] ? [...ForwardAccumulator, ...BackwardAccumulator] : [...ForwardAccumulator, TArray[number], ...BackwardAccumulator] // Add the rest element between the accumulated elements.
448
+ : TArray extends readonly [(infer First)?, ...infer Rest] ? _CollapseRestElement<Rest, [...ForwardAccumulator, '0' extends OptionalKeysOf<TArray> ? If<IsExactOptionalPropertyTypesEnabled, First, First | undefined> // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
449
+ : First], BackwardAccumulator> : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
450
+ : never; // Should never happen
451
+ type _Numeric = number | bigint;
452
+ type Zero = 0 | 0n;
453
+ /**
454
+ Matches the hidden `Infinity` type.
455
+
456
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
457
+
458
+ @see {@link NegativeInfinity}
459
+
460
+ @category Numeric
461
+ */
462
+ // See https://github.com/microsoft/TypeScript/issues/31752
463
+ // eslint-disable-next-line no-loss-of-precision
464
+ type PositiveInfinity = 1e999;
465
+ /**
466
+ Matches the hidden `-Infinity` type.
467
+
468
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
469
+
470
+ @see {@link PositiveInfinity}
471
+
472
+ @category Numeric
473
+ */
474
+ // See https://github.com/microsoft/TypeScript/issues/31752
475
+ // eslint-disable-next-line no-loss-of-precision
476
+ type NegativeInfinity = -1e999;
477
+ /**
478
+ A negative `number`/`bigint` (`-∞ < x < 0`)
479
+
480
+ Use-case: Validating and documenting parameters.
481
+
482
+ @see {@link NegativeInteger}
483
+ @see {@link NonNegative}
484
+
485
+ @category Numeric
486
+ */
487
+ type Negative<T extends _Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
488
+ /**
489
+ Returns a boolean for whether the given number is a negative number.
490
+
491
+ @see {@link Negative}
492
+
493
+ @example
494
+ ```
495
+ import type {IsNegative} from 'type-fest';
496
+
497
+ type ShouldBeFalse = IsNegative<1>;
498
+ type ShouldBeTrue = IsNegative<-1>;
499
+ ```
500
+
501
+ @category Numeric
502
+ */
503
+ type IsNegative<T extends _Numeric> = T extends Negative<T> ? true : false;
504
+ /**
505
+ Create a tuple type of the specified length with elements of the specified type.
506
+
507
+ @example
508
+ ```
509
+ import type {TupleOf} from 'type-fest';
510
+
511
+ type RGB = TupleOf<3, number>;
512
+ //=> [number, number, number]
513
+
514
+ type Line = TupleOf<2, {x: number; y: number}>;
515
+ //=> [{x: number; y: number}, {x: number; y: number}]
516
+
517
+ type TicTacToeBoard = TupleOf<3, TupleOf<3, 'X' | 'O' | null>>;
518
+ //=> [['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null], ['X' | 'O' | null, 'X' | 'O' | null, 'X' | 'O' | null]]
519
+ ```
520
+
521
+ @example
522
+ ```
523
+ import type {TupleOf} from 'type-fest';
524
+
525
+ type Range<Start extends number, End extends number> = Exclude<keyof TupleOf<End>, keyof TupleOf<Start>>;
526
+
527
+ type ZeroToFour = Range<0, 5>;
528
+ //=> '0' | '1' | '2' | '3' | '4'
529
+
530
+ type ThreeToEight = Range<3, 9>;
531
+ //=> '3' | '4' | '5' | '6' | '7' | '8'
532
+ ```
533
+
534
+ Note: If the specified length is the non-literal `number` type, the result will not be a tuple but a regular array.
535
+
536
+ @example
537
+ ```
538
+ import type {TupleOf} from 'type-fest';
539
+
540
+ type StringArray = TupleOf<number, string>;
541
+ //=> string[]
542
+ ```
543
+
544
+ Note: If the type for elements is not specified, it will default to `unknown`.
545
+
546
+ @example
547
+ ```
548
+ import type {TupleOf} from 'type-fest';
549
+
550
+ type UnknownTriplet = TupleOf<3>;
551
+ //=> [unknown, unknown, unknown]
552
+ ```
553
+
554
+ Note: If the specified length is negative, the result will be an empty tuple.
555
+
556
+ @example
557
+ ```
558
+ import type {TupleOf} from 'type-fest';
559
+
560
+ type EmptyTuple = TupleOf<-3, string>;
561
+ //=> []
562
+ ```
563
+
564
+ Note: If the specified length has a decimal part, the decimal part will be ignored.
565
+
566
+ @example
567
+ ```
568
+ import type {TupleOf} from 'type-fest';
569
+
570
+ type DecimalLength = TupleOf<3.5, string>;
571
+ //=> [string, string, string]
572
+ ```
573
+
574
+ Note: If you need a readonly tuple, simply wrap this type with `Readonly`, for example, to create `readonly [number, number, number]` use `Readonly<TupleOf<3, number>>`.
575
+
576
+ @category Array
577
+ */
578
+ type TupleOf<Length extends number, Fill = unknown> = IfNotAnyOrNever<Length, _TupleOf<If<IsNegative<Length>, 0, Length>, Fill>, Fill[], []>;
579
+ type _TupleOf<Length extends number, Fill> = number extends Length ? Fill[] : BuildTupleDigitByDigit<`${Length}`, Fill>;
580
+ type BuildTupleDigitByDigit<Length extends string, Fill, Accumulator extends UnknownArray = []> = Length extends `${infer First extends DigitCharacter}${infer Rest}` ? BuildTupleDigitByDigit<Rest, Fill, [...RepeatTupleTenTimes<Accumulator>, ...DigitTupleOf<First, Fill>]> : Accumulator;
581
+ type RepeatTupleTenTimes<Tuple extends UnknownArray> = [...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple, ...Tuple];
582
+ type DigitTupleOf<Digit extends DigitCharacter, Fill> = [[], [Fill], [Fill, Fill], [Fill, Fill, Fill], [Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill], [Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill, Fill]][Digit];
583
+ /**
584
+ Return a string representation of the given string or number.
585
+
586
+ Note: This type is not the return type of the `.toString()` function.
587
+ */
588
+ type ToString<T> = T extends string | number ? `${T}` : never;
589
+ /**
590
+ Converts a numeric string to a number.
591
+
592
+ @example
593
+ ```
594
+ type PositiveInt = StringToNumber<'1234'>;
595
+ //=> 1234
596
+
597
+ type NegativeInt = StringToNumber<'-1234'>;
598
+ //=> -1234
599
+
600
+ type PositiveFloat = StringToNumber<'1234.56'>;
601
+ //=> 1234.56
602
+
603
+ type NegativeFloat = StringToNumber<'-1234.56'>;
604
+ //=> -1234.56
605
+
606
+ type PositiveInfinity = StringToNumber<'Infinity'>;
607
+ //=> Infinity
608
+
609
+ type NegativeInfinity = StringToNumber<'-Infinity'>;
610
+ //=> -Infinity
611
+ ```
612
+
613
+ @category String
614
+ @category Numeric
615
+ @category Template literal
616
+ */
617
+ type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends 'Infinity' ? PositiveInfinity : S extends '-Infinity' ? NegativeInfinity : never;
618
+ /**
619
+ Returns an array of the characters of the string.
620
+
621
+ @example
622
+ ```
623
+ type A = StringToArray<'abcde'>;
624
+ //=> ['a', 'b', 'c', 'd', 'e']
625
+
626
+ type B = StringToArray<string>;
627
+ //=> never
628
+ ```
629
+
630
+ @category String
631
+ */
632
+ type StringToArray<S extends string, Result extends string[] = []> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [...Result, F]> : Result;
633
+ /**
634
+ Returns the length of the given string.
635
+
636
+ @example
637
+ ```
638
+ type A = StringLength<'abcde'>;
639
+ //=> 5
640
+
641
+ type B = StringLength<string>;
642
+ //=> never
643
+ ```
644
+
645
+ @category String
646
+ @category Template literal
647
+ */
648
+ type StringLength<S extends string> = string extends S ? never : StringToArray<S>['length'];
649
+ /**
650
+ Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
651
+
652
+ @example
653
+ ```
654
+ type A = SameLengthPositiveNumericStringGt<'50', '10'>;
655
+ //=> true
656
+
657
+ type B = SameLengthPositiveNumericStringGt<'10', '10'>;
658
+ //=> false
659
+ ```
660
+ */
661
+ type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}` ? B extends `${infer FirstB}${infer RestB}` ? FirstA extends FirstB ? SameLengthPositiveNumericStringGt<RestA, RestB> : PositiveNumericCharacterGt<FirstA, FirstB> : never : false;
662
+ type NumericString = '0123456789';
663
+ /**
664
+ Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
665
+
666
+ @example
667
+ ```
668
+ type A = PositiveNumericStringGt<'500', '1'>;
669
+ //=> true
670
+
671
+ type B = PositiveNumericStringGt<'1', '1'>;
672
+ //=> false
673
+
674
+ type C = PositiveNumericStringGt<'1', '500'>;
675
+ //=> false
676
+ ```
677
+ */
678
+ type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [TupleOf<StringLength<A>, 0>, TupleOf<StringLength<B>, 0>] extends (infer R extends [readonly unknown[], readonly unknown[]]) ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]] ? 0 extends Remain['length'] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
679
+ /**
680
+ Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
681
+
682
+ @example
683
+ ```
684
+ type A = PositiveNumericCharacterGt<'5', '1'>;
685
+ //=> true
686
+
687
+ type B = PositiveNumericCharacterGt<'1', '1'>;
688
+ //=> false
689
+ ```
690
+ */
691
+ type PositiveNumericCharacterGt<A extends string, B extends string> = NumericString extends `${infer HeadA}${A}${infer TailA}` ? NumericString extends `${infer HeadB}${B}${infer TailB}` ? HeadA extends `${HeadB}${infer _}${infer __}` ? true : false : never : never;
692
+ /**
693
+ Check whether the given type is a number or a number string.
694
+
695
+ Supports floating-point as a string.
696
+
697
+ @example
698
+ ```
699
+ type A = IsNumberLike<'1'>;
700
+ //=> true
701
+
702
+ type B = IsNumberLike<'-1.1'>;
703
+ //=> true
704
+
705
+ type C = IsNumberLike<'5e-20'>;
706
+ //=> true
707
+
708
+ type D = IsNumberLike<1>;
709
+ //=> true
710
+
711
+ type E = IsNumberLike<'a'>;
712
+ //=> false
713
+ */
714
+ type IsNumberLike<N> = IfNotAnyOrNever<N, N extends number | `${number}` ? true : false, boolean, false>;
715
+ /**
716
+ Returns the number with reversed sign.
717
+
718
+ @example
719
+ ```
720
+ type A = ReverseSign<-1>;
721
+ //=> 1
722
+
723
+ type B = ReverseSign<1>;
724
+ //=> -1
725
+
726
+ type C = ReverseSign<NegativeInfinity>;
727
+ //=> PositiveInfinity
728
+
729
+ type D = ReverseSign<PositiveInfinity>;
730
+ //=> NegativeInfinity
731
+ ```
732
+ */
733
+ type ReverseSign<N extends number> =
734
+ // Handle edge cases
735
+ N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity :
736
+ // Handle negative numbers
737
+ `${N}` extends `-${infer P extends number}` ? P :
738
+ // Handle positive numbers
739
+ `-${N}` extends `${infer R extends number}` ? R : never;
740
+ /**
741
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
742
+
743
+ @example
744
+ ```
745
+ import type {Simplify} from 'type-fest';
746
+
747
+ type PositionProps = {
748
+ top: number;
749
+ left: number;
750
+ };
751
+
752
+ type SizeProps = {
753
+ width: number;
754
+ height: number;
755
+ };
756
+
757
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
758
+ type Props = Simplify<PositionProps & SizeProps>;
759
+ ```
760
+
761
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
762
+
763
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
764
+
765
+ @example
766
+ ```
767
+ import type {Simplify} from 'type-fest';
768
+
769
+ interface SomeInterface {
770
+ foo: number;
771
+ bar?: string;
772
+ baz: number | undefined;
773
+ }
774
+
775
+ type SomeType = {
776
+ foo: number;
777
+ bar?: string;
778
+ baz: number | undefined;
779
+ };
780
+
781
+ const literal = {foo: 123, bar: 'hello', baz: 456};
782
+ const someType: SomeType = literal;
783
+ const someInterface: SomeInterface = literal;
784
+
785
+ declare function fn(object: Record<string, unknown>): void;
786
+
787
+ fn(literal); // Good: literal object type is sealed
788
+ fn(someType); // Good: type is sealed
789
+ // @ts-expect-error
790
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
791
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
792
+ ```
793
+
794
+ @link https://github.com/microsoft/TypeScript/issues/15300
795
+ @see {@link SimplifyDeep}
796
+ @category Object
797
+ */
798
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
799
+ /**
800
+ Returns a boolean for whether the two given types are equal.
801
+
802
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
803
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
804
+
805
+ Use-cases:
806
+ - If you want to make a conditional branch based on the result of a comparison of two types.
807
+
808
+ @example
809
+ ```
810
+ import type {IsEqual} from 'type-fest';
811
+
812
+ // This type returns a boolean for whether the given array includes the given item.
813
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
814
+ type Includes<Value extends readonly any[], Item> =
815
+ Value extends readonly [Value[0], ...infer rest]
816
+ ? IsEqual<Value[0], Item> extends true
817
+ ? true
818
+ : Includes<rest, Item>
819
+ : false;
820
+ ```
821
+
822
+ @category Type Guard
823
+ @category Utilities
824
+ */
825
+ type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
826
+ // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
827
+ type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
828
+ /**
829
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
830
+
831
+ This is the counterpart of `PickIndexSignature`.
832
+
833
+ Use-cases:
834
+ - Remove overly permissive signatures from third-party types.
835
+
836
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
837
+
838
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
839
+
840
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
841
+
842
+ ```
843
+ const indexed: Record<string, unknown> = {}; // Allowed
844
+
845
+ // @ts-expect-error
846
+ const keyed: Record<'foo', unknown> = {}; // Error
847
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
848
+ ```
849
+
850
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
851
+
852
+ ```
853
+ type Indexed = {} extends Record<string, unknown>
854
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
855
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
856
+
857
+ type IndexedResult = Indexed;
858
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
859
+
860
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
861
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
862
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
863
+
864
+ type KeyedResult = Keyed;
865
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
866
+ ```
867
+
868
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
869
+
870
+ ```
871
+ type OmitIndexSignature<ObjectType> = {
872
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
873
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
874
+ };
875
+ ```
876
+
877
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
878
+
879
+ ```
880
+ type OmitIndexSignature<ObjectType> = {
881
+ [KeyType in keyof ObjectType
882
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
883
+ as {} extends Record<KeyType, unknown>
884
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
885
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
886
+ ]: ObjectType[KeyType];
887
+ };
888
+ ```
889
+
890
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
891
+
892
+ @example
893
+ ```
894
+ import type {OmitIndexSignature} from 'type-fest';
895
+
896
+ type Example = {
897
+ // These index signatures will be removed.
898
+ [x: string]: any;
899
+ [x: number]: any;
900
+ [x: symbol]: any;
901
+ [x: `head-${string}`]: string;
902
+ [x: `${string}-tail`]: string;
903
+ [x: `head-${string}-tail`]: string;
904
+ [x: `${bigint}`]: string;
905
+ [x: `embedded-${number}`]: string;
906
+
907
+ // These explicitly defined keys will remain.
908
+ foo: 'bar';
909
+ qux?: 'baz';
910
+ };
911
+
912
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
913
+ //=> {foo: 'bar'; qux?: 'baz'}
914
+ ```
915
+
916
+ @see {@link PickIndexSignature}
917
+ @category Object
918
+ */
919
+ type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType]; };
920
+ /**
921
+ Pick only index signatures from the given object type, leaving out all explicitly defined properties.
922
+
923
+ This is the counterpart of `OmitIndexSignature`.
924
+
925
+ @example
926
+ ```
927
+ import type {PickIndexSignature} from 'type-fest';
928
+
929
+ declare const symbolKey: unique symbol;
930
+
931
+ type Example = {
932
+ // These index signatures will remain.
933
+ [x: string]: unknown;
934
+ [x: number]: unknown;
935
+ [x: symbol]: unknown;
936
+ [x: `head-${string}`]: string;
937
+ [x: `${string}-tail`]: string;
938
+ [x: `head-${string}-tail`]: string;
939
+ [x: `${bigint}`]: string;
940
+ [x: `embedded-${number}`]: string;
941
+
942
+ // These explicitly defined keys will be removed.
943
+ ['kebab-case-key']: string;
944
+ [symbolKey]: string;
945
+ foo: 'bar';
946
+ qux?: 'baz';
947
+ };
948
+
949
+ type ExampleIndexSignature = PickIndexSignature<Example>;
950
+ // {
951
+ // [x: string]: unknown;
952
+ // [x: number]: unknown;
953
+ // [x: symbol]: unknown;
954
+ // [x: `head-${string}`]: string;
955
+ // [x: `${string}-tail`]: string;
956
+ // [x: `head-${string}-tail`]: string;
957
+ // [x: `${bigint}`]: string;
958
+ // [x: `embedded-${number}`]: string;
959
+ // }
960
+ ```
961
+
962
+ @see {@link OmitIndexSignature}
963
+ @category Object
964
+ */
965
+ type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType]; };
966
+ // Merges two objects without worrying about index signatures.
967
+ type SimpleMerge<Destination, Source> = Simplify<{ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key]; } & Source>;
968
+ /**
969
+ Merge two types into a new type. Keys of the second type overrides keys of the first type.
970
+
971
+ This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
972
+
973
+ @example
974
+ ```
975
+ import type {Merge} from 'type-fest';
976
+
977
+ type Foo = {
978
+ a: string;
979
+ b: number;
980
+ };
981
+
982
+ type Bar = {
983
+ a: number; // Conflicts with Foo['a']
984
+ c: boolean;
985
+ };
986
+
987
+ // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
988
+ type WithIntersection = (Foo & Bar)['a'];
989
+ //=> never
990
+
991
+ // With `Merge`, `a` is cleanly overridden to `number`.
992
+ type WithMerge = Merge<Foo, Bar>['a'];
993
+ //=> number
994
+ ```
995
+
996
+ @example
997
+ ```
998
+ import type {Merge} from 'type-fest';
999
+
1000
+ type Foo = {
1001
+ [x: string]: unknown;
1002
+ [x: number]: unknown;
1003
+ foo: string;
1004
+ bar: symbol;
1005
+ };
1006
+
1007
+ type Bar = {
1008
+ [x: number]: number;
1009
+ [x: symbol]: unknown;
1010
+ bar: Date;
1011
+ baz: boolean;
1012
+ };
1013
+
1014
+ export type FooBar = Merge<Foo, Bar>;
1015
+ //=> {
1016
+ // [x: string]: unknown;
1017
+ // [x: number]: number;
1018
+ // [x: symbol]: unknown;
1019
+ // foo: string;
1020
+ // bar: Date;
1021
+ // baz: boolean;
1022
+ // }
1023
+ ```
1024
+
1025
+ Note: If you want a merge type that more accurately reflects the runtime behavior of object spread or `Object.assign`, refer to the {@link ObjectMerge} type.
1026
+
1027
+ @see {@link ObjectMerge}
1028
+ @category Object
1029
+ */
1030
+ type Merge<Destination, Source> = Destination extends unknown // For distributing `Destination`
1031
+ ? Source extends unknown // For distributing `Source`
1032
+ ? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>> : never // Should never happen
1033
+ : never; // Should never happen
1034
+ type _Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
1035
+ /**
1036
+ Merges user specified options with default options.
1037
+
1038
+ @example
1039
+ ```
1040
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1041
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
1042
+ type SpecifiedOptions = {leavesOnly: true};
1043
+
1044
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1045
+ //=> {maxRecursionDepth: 10; leavesOnly: true}
1046
+ ```
1047
+
1048
+ @example
1049
+ ```
1050
+ // Complains if default values are not provided for optional options
1051
+
1052
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1053
+ type DefaultPathsOptions = {maxRecursionDepth: 10};
1054
+ type SpecifiedOptions = {};
1055
+
1056
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1057
+ // ~~~~~~~~~~~~~~~~~~~
1058
+ // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
1059
+ ```
1060
+
1061
+ @example
1062
+ ```
1063
+ // Complains if an option's default type does not conform to the expected type
1064
+
1065
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1066
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
1067
+ type SpecifiedOptions = {};
1068
+
1069
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1070
+ // ~~~~~~~~~~~~~~~~~~~
1071
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
1072
+ ```
1073
+
1074
+ @example
1075
+ ```
1076
+ // Complains if an option's specified type does not conform to the expected type
1077
+
1078
+ type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
1079
+ type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
1080
+ type SpecifiedOptions = {leavesOnly: 'yes'};
1081
+
1082
+ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
1083
+ // ~~~~~~~~~~~~~~~~
1084
+ // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
1085
+ ```
1086
+ */
1087
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> extends (infer Result extends Required<Options> // `extends Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
1088
+ ) ? Result : never;
1089
+ type _ApplyDefaultOptions<Options, Defaults, SpecifiedOptions> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Merge<Defaults, { [Key in keyof SpecifiedOptions as undefined extends Required<Options>[Key & keyof Options] ? Key : undefined extends SpecifiedOptions[Key] ? never : Key]: SpecifiedOptions[Key]; }>>>;
1090
+ /**
1091
+ @see {@link SomeExtend}
1092
+ */
1093
+ type SomeExtendOptions = {
1094
+ /**
1095
+ Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
1096
+
1097
+ - When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
1098
+ - When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
1099
+
1100
+ @default true
1101
+
1102
+ @example
1103
+ ```
1104
+ import type {SomeExtend} from 'type-fest';
1105
+
1106
+ type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
1107
+ //=> false
1108
+
1109
+ type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
1110
+ //=> true
1111
+
1112
+ type C = SomeExtend<[1, never], never, {strictNever: true}>;
1113
+ //=> true
1114
+
1115
+ type D = SomeExtend<[1, never], never, {strictNever: false}>;
1116
+ //=> true
1117
+
1118
+ type E = SomeExtend<[never], any, {strictNever: true}>;
1119
+ //=> true
1120
+
1121
+ type F = SomeExtend<[never], any, {strictNever: false}>;
1122
+ //=> true
1123
+ ```
1124
+ */
1125
+ strictNever?: boolean;
1126
+ };
1127
+ type DefaultSomeExtendOptions = {
1128
+ strictNever: true;
1129
+ };
1130
+ /**
1131
+ Returns a boolean for whether some element in an array type extends another type.
1132
+
1133
+ @example
1134
+ ```
1135
+ import type {SomeExtend} from 'type-fest';
1136
+
1137
+ type A = SomeExtend<['1', '2', 3], number>;
1138
+ //=> true
1139
+
1140
+ type B = SomeExtend<[1, 2, 3], string>;
1141
+ //=> false
1142
+
1143
+ type C = SomeExtend<[string, number | string], number>;
1144
+ //=> boolean
1145
+
1146
+ type D = SomeExtend<[true, boolean, true], false>;
1147
+ //=> boolean
1148
+ ```
1149
+
1150
+ Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
1151
+
1152
+ ```
1153
+ // @exactOptionalPropertyTypes: true
1154
+ import type {SomeExtend} from 'type-fest';
1155
+
1156
+ type A = SomeExtend<[1?, 2?, '3'?], string>;
1157
+ //=> true
1158
+ ```
1159
+
1160
+ ```
1161
+ // @exactOptionalPropertyTypes: false
1162
+ import type {SomeExtend} from 'type-fest';
1163
+
1164
+ type A = SomeExtend<[1?, 2?, '3'?], string>;
1165
+ //=> boolean
1166
+
1167
+ type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
1168
+ //=> true
1169
+ ```
1170
+
1171
+ @see {@link SomeExtendOptions}
1172
+
1173
+ @category Utilities
1174
+ @category Array
1175
+ */
1176
+ type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> = _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
1177
+ type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true ?
1178
+ // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
1179
+ true : _SomeExtend<Rest, Type, Options> : First extends Type ? true : _SomeExtend<Rest, Type, Options> : false, false, false>;
1180
+ /**
1181
+ Returns a boolean for whether any of the given elements is `true`.
1182
+
1183
+ Use-cases:
1184
+ - Check if at least one condition in a list of booleans is met.
1185
+
1186
+ @example
1187
+ ```
1188
+ import type {OrAll} from 'type-fest';
1189
+
1190
+ type FFT = OrAll<[false, false, true]>;
1191
+ //=> true
1192
+
1193
+ type FFF = OrAll<[false, false, false]>;
1194
+ //=> false
1195
+ ```
1196
+
1197
+ Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
1198
+ For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
1199
+
1200
+ @example
1201
+ ```
1202
+ import type {OrAll} from 'type-fest';
1203
+
1204
+ type A = OrAll<[false, boolean]>;
1205
+ //=> boolean
1206
+
1207
+ type B = OrAll<[true, boolean]>;
1208
+ //=> true
1209
+ ```
1210
+
1211
+ Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
1212
+
1213
+ @example
1214
+ ```
1215
+ import type {OrAll} from 'type-fest';
1216
+
1217
+ type A = OrAll<[never, never, true]>;
1218
+ //=> true
1219
+
1220
+ type B = OrAll<[never, never, false]>;
1221
+ //=> false
1222
+
1223
+ type C = OrAll<[never, never, never]>;
1224
+ //=> false
1225
+
1226
+ type D = OrAll<[never, never, boolean]>;
1227
+ //=> boolean
1228
+ ```
1229
+
1230
+ Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
1231
+
1232
+ @example
1233
+ ```
1234
+ import type {OrAll} from 'type-fest';
1235
+
1236
+ type A = OrAll<[false, any]>;
1237
+ //=> boolean
1238
+
1239
+ type B = OrAll<[true, any]>;
1240
+ //=> true
1241
+ ```
1242
+
1243
+ Note: `OrAll<[]>` evaluates to `false` because there are no `true` elements in an empty tuple. See [Wikipedia: Clause (logic) > Empty clauses](https://en.wikipedia.org/wiki/Clause_(logic)#Empty_clauses:~:text=The%20truth%20evaluation%20of%20an%20empty%20disjunctive%20clause%20is%20always%20false.).
1244
+
1245
+ @see {@link Or}
1246
+ @see {@link AndAll}
1247
+ */
1248
+ type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
1249
+ /**
1250
+ Returns a boolean for whether either of two given types is `true`.
1251
+
1252
+ Use-case: Constructing complex conditional types where at least one condition must be satisfied.
1253
+
1254
+ @example
1255
+ ```
1256
+ import type {Or} from 'type-fest';
1257
+
1258
+ type TT = Or<true, true>;
1259
+ //=> true
1260
+
1261
+ type TF = Or<true, false>;
1262
+ //=> true
1263
+
1264
+ type FT = Or<false, true>;
1265
+ //=> true
1266
+
1267
+ type FF = Or<false, false>;
1268
+ //=> false
1269
+ ```
1270
+
1271
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
1272
+ For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
1273
+
1274
+ @example
1275
+ ```
1276
+ import type {Or} from 'type-fest';
1277
+
1278
+ type A = Or<false, boolean>;
1279
+ //=> boolean
1280
+
1281
+ type B = Or<boolean, false>;
1282
+ //=> boolean
1283
+
1284
+ type C = Or<true, boolean>;
1285
+ //=> true
1286
+
1287
+ type D = Or<boolean, true>;
1288
+ //=> true
1289
+
1290
+ type E = Or<boolean, boolean>;
1291
+ //=> boolean
1292
+ ```
1293
+
1294
+ Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
1295
+
1296
+ @example
1297
+ ```
1298
+ import type {Or} from 'type-fest';
1299
+
1300
+ type A = Or<true, never>;
1301
+ //=> true
1302
+
1303
+ type B = Or<never, true>;
1304
+ //=> true
1305
+
1306
+ type C = Or<false, never>;
1307
+ //=> false
1308
+
1309
+ type D = Or<never, false>;
1310
+ //=> false
1311
+
1312
+ type E = Or<boolean, never>;
1313
+ //=> boolean
1314
+
1315
+ type F = Or<never, boolean>;
1316
+ //=> boolean
1317
+
1318
+ type G = Or<never, never>;
1319
+ //=> false
1320
+ ```
1321
+
1322
+ @see {@link OrAll}
1323
+ @see {@link And}
1324
+ @see {@link Xor}
1325
+ */
1326
+ type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
1327
+ /**
1328
+ @see {@link AllExtend}
1329
+ */
1330
+ type AllExtendOptions = {
1331
+ /**
1332
+ Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
1333
+
1334
+ - When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
1335
+ - When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
1336
+
1337
+ @default true
1338
+
1339
+ @example
1340
+ ```
1341
+ import type {AllExtend} from 'type-fest';
1342
+
1343
+ type A = AllExtend<[1, 2, never], number, {strictNever: true}>;
1344
+ //=> false
1345
+
1346
+ type B = AllExtend<[1, 2, never], number, {strictNever: false}>;
1347
+ //=> true
1348
+
1349
+ type C = AllExtend<[never, never], never, {strictNever: true}>;
1350
+ //=> true
1351
+
1352
+ type D = AllExtend<[never, never], never, {strictNever: false}>;
1353
+ //=> true
1354
+
1355
+ type E = AllExtend<['a', 'b', never], any, {strictNever: true}>;
1356
+ //=> true
1357
+
1358
+ type F = AllExtend<['a', 'b', never], any, {strictNever: false}>;
1359
+ //=> true
1360
+
1361
+ type G = AllExtend<[never, 1], never, {strictNever: true}>;
1362
+ //=> false
1363
+
1364
+ type H = AllExtend<[never, 1], never, {strictNever: false}>;
1365
+ //=> false
1366
+ ```
1367
+ */
1368
+ strictNever?: boolean;
1369
+ };
1370
+ type DefaultAllExtendOptions = {
1371
+ strictNever: true;
1372
+ };
1373
+ /**
1374
+ Returns a boolean for whether every element in an array type extends another type.
1375
+
1376
+ @example
1377
+ ```
1378
+ import type {AllExtend} from 'type-fest';
1379
+
1380
+ type A = AllExtend<[1, 2, 3], number>;
1381
+ //=> true
1382
+
1383
+ type B = AllExtend<[1, 2, '3'], number>;
1384
+ //=> false
1385
+
1386
+ type C = AllExtend<[number, number | string], number>;
1387
+ //=> boolean
1388
+
1389
+ type D = AllExtend<[true, boolean, true], true>;
1390
+ //=> boolean
1391
+ ```
1392
+
1393
+ Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
1394
+
1395
+ ```
1396
+ // @exactOptionalPropertyTypes: true
1397
+ import type {AllExtend} from 'type-fest';
1398
+
1399
+ type A = AllExtend<[1?, 2?, 3?], number>;
1400
+ //=> true
1401
+ ```
1402
+
1403
+ ```
1404
+ // @exactOptionalPropertyTypes: false
1405
+ import type {AllExtend} from 'type-fest';
1406
+
1407
+ type A = AllExtend<[1?, 2?, 3?], number>;
1408
+ //=> boolean
1409
+
1410
+ type B = AllExtend<[1?, 2?, 3?], number | undefined>;
1411
+ //=> true
1412
+ ```
1413
+
1414
+ @see {@link AllExtendOptions}
1415
+
1416
+ @category Utilities
1417
+ @category Array
1418
+ */
1419
+ type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> = _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
1420
+ type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, TArray extends readonly [infer First, ...infer Rest] ? IsNever<First> extends true ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true ?
1421
+ // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
1422
+ _AllExtend<Rest, Type, Options> : false : First extends Type ? _AllExtend<Rest, Type, Options> : false : true, false, false>;
1423
+ /**
1424
+ Returns a boolean for whether all of the given elements are `true`.
1425
+
1426
+ Use-cases:
1427
+ - Check if all conditions in a list of booleans are met.
1428
+
1429
+ @example
1430
+ ```
1431
+ import type {AndAll} from 'type-fest';
1432
+
1433
+ type TTT = AndAll<[true, true, true]>;
1434
+ //=> true
1435
+
1436
+ type TTF = AndAll<[true, true, false]>;
1437
+ //=> false
1438
+
1439
+ type TFT = AndAll<[true, false, true]>;
1440
+ //=> false
1441
+ ```
1442
+
1443
+ Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
1444
+ For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
1445
+
1446
+ @example
1447
+ ```
1448
+ import type {AndAll} from 'type-fest';
1449
+
1450
+ type A = AndAll<[true, boolean]>;
1451
+ //=> boolean
1452
+
1453
+ type B = AndAll<[false, boolean]>;
1454
+ //=> false
1455
+ ```
1456
+
1457
+ Note: If any of the elements is `never`, the result becomes `false`.
1458
+
1459
+ @example
1460
+ ```
1461
+ import type {AndAll} from 'type-fest';
1462
+
1463
+ type A = AndAll<[true, true, never]>;
1464
+ //=> false
1465
+
1466
+ type B = AndAll<[false, never, never]>;
1467
+ //=> false
1468
+
1469
+ type C = AndAll<[never, never, never]>;
1470
+ //=> false
1471
+
1472
+ type D = AndAll<[boolean, true, never]>;
1473
+ //=> false
1474
+ ```
1475
+
1476
+ Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
1477
+
1478
+ @example
1479
+ ```
1480
+ import type {AndAll} from 'type-fest';
1481
+
1482
+ type A = AndAll<[false, any]>;
1483
+ //=> false
1484
+
1485
+ type B = AndAll<[true, any]>;
1486
+ //=> boolean
1487
+ ```
1488
+
1489
+ Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
1490
+
1491
+ @see {@link And}
1492
+ @see {@link OrAll}
1493
+ */
1494
+ type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
1495
+ /**
1496
+ Returns a boolean for whether two given types are both `true`.
1497
+
1498
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
1499
+
1500
+ @example
1501
+ ```
1502
+ import type {And} from 'type-fest';
1503
+
1504
+ type TT = And<true, true>;
1505
+ //=> true
1506
+
1507
+ type TF = And<true, false>;
1508
+ //=> false
1509
+
1510
+ type FT = And<false, true>;
1511
+ //=> false
1512
+
1513
+ type FF = And<false, false>;
1514
+ //=> false
1515
+ ```
1516
+
1517
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
1518
+ For example, `And<true, boolean>` expands to `And<true, true> | And<true, false>`, which simplifies to `true | false` (i.e., `boolean`).
1519
+
1520
+ @example
1521
+ ```
1522
+ import type {And} from 'type-fest';
1523
+
1524
+ type A = And<true, boolean>;
1525
+ //=> boolean
1526
+
1527
+ type B = And<boolean, true>;
1528
+ //=> boolean
1529
+
1530
+ type C = And<false, boolean>;
1531
+ //=> false
1532
+
1533
+ type D = And<boolean, false>;
1534
+ //=> false
1535
+
1536
+ type E = And<boolean, boolean>;
1537
+ //=> boolean
1538
+ ```
1539
+
1540
+ Note: If either of the types is `never`, the result becomes `false`.
1541
+
1542
+ @example
1543
+ ```
1544
+ import type {And} from 'type-fest';
1545
+
1546
+ type A = And<true, never>;
1547
+ //=> false
1548
+
1549
+ type B = And<never, true>;
1550
+ //=> false
1551
+
1552
+ type C = And<false, never>;
1553
+ //=> false
1554
+
1555
+ type D = And<never, false>;
1556
+ //=> false
1557
+
1558
+ type E = And<boolean, never>;
1559
+ //=> false
1560
+
1561
+ type F = And<never, boolean>;
1562
+ //=> false
1563
+
1564
+ type G = And<never, never>;
1565
+ //=> false
1566
+ ```
1567
+
1568
+ @see {@link AndAll}
1569
+ @see {@link Or}
1570
+ @see {@link Xor}
1571
+ */
1572
+ type And<A extends boolean, B extends boolean> = AndAll<[A, B]>;
1573
+ /**
1574
+ Returns the absolute value of the specified number or bigint.
1575
+
1576
+ @example
1577
+ ```
1578
+ import type {Absolute} from 'type-fest';
1579
+
1580
+ type A = Absolute<-1>;
1581
+ //=> 1
1582
+
1583
+ type B = Absolute<1>;
1584
+ //=> 1
1585
+
1586
+ type C = Absolute<0>;
1587
+ //=> 0
1588
+
1589
+ type D = Absolute<-1.025>;
1590
+ //=> 1.025
1591
+
1592
+ type E = Absolute<-9999n>;
1593
+ //=> 9999n
1594
+ ```
1595
+
1596
+ Returns back the same type if the input is not a literal type.
1597
+
1598
+ @example
1599
+ ```
1600
+ import type {Absolute} from 'type-fest';
1601
+
1602
+ type A = Absolute<number>;
1603
+ //=> number
1604
+
1605
+ type B = Absolute<bigint>;
1606
+ //=> bigint
1607
+
1608
+ type C = Absolute<number | bigint>;
1609
+ //=> number | bigint
1610
+ ```
1611
+
1612
+ @category Numeric
1613
+ */
1614
+ type Absolute<N extends number | bigint> = N extends bigint // Also, distributes `N`
1615
+ ? `${N}` extends `-${infer Magnitude extends bigint}` ? Magnitude : N : `${N}` extends `-${infer Magnitude}` // This doesn't use the `extends number` constraint approach because that fails with the `-Infinity` case
1616
+ ? StringToNumber<Magnitude> : N;
1617
+ /**
1618
+ Returns a boolean for whether a given number is greater than another number.
1619
+
1620
+ @example
1621
+ ```
1622
+ import type {GreaterThan} from 'type-fest';
1623
+
1624
+ type A = GreaterThan<1, -5>;
1625
+ //=> true
1626
+
1627
+ type B = GreaterThan<1, 1>;
1628
+ //=> false
1629
+
1630
+ type C = GreaterThan<1, 5>;
1631
+ //=> false
1632
+ ```
1633
+
1634
+ Note: If either argument is the non-literal `number` type, the result is `boolean`.
1635
+
1636
+ @example
1637
+ ```
1638
+ import type {GreaterThan} from 'type-fest';
1639
+
1640
+ type A = GreaterThan<number, 1>;
1641
+ //=> boolean
1642
+
1643
+ type B = GreaterThan<1, number>;
1644
+ //=> boolean
1645
+
1646
+ type C = GreaterThan<number, number>;
1647
+ //=> boolean
1648
+ ```
1649
+
1650
+ @example
1651
+ ```
1652
+ import type {GreaterThan} from 'type-fest';
1653
+
1654
+ // Use `GreaterThan` to constrain a function parameter to positive numbers.
1655
+ declare function setPositive<N extends number>(value: GreaterThan<N, 0> extends true ? N : never): void;
1656
+
1657
+ setPositive(1); // ✅ Allowed
1658
+ setPositive(2); // ✅ Allowed
1659
+
1660
+ // @ts-expect-error
1661
+ setPositive(0);
1662
+
1663
+ // @ts-expect-error
1664
+ setPositive(-1);
1665
+ ```
1666
+ */
1667
+ type GreaterThan<A extends number, B extends number> = A extends number // For distributing `A`
1668
+ ? B extends number // For distributing `B`
1669
+ ? number extends A | B ? boolean : [IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>, IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>] extends (infer R extends [boolean, boolean, boolean, boolean]) ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? true : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? false : true extends R[number] ? false : [IsNegative<A>, IsNegative<B>] extends (infer R extends [boolean, boolean]) ? [true, false] extends R ? false : [false, true] extends R ? true : [false, false] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${Absolute<B>}`, `${Absolute<A>}`> : never : never : never // Should never happen
1670
+ : never; // Should never happen
1671
+ /**
1672
+ Returns a boolean for whether a given number is greater than or equal to another number.
1673
+
1674
+ @example
1675
+ ```
1676
+ import type {GreaterThanOrEqual} from 'type-fest';
1677
+
1678
+ type A = GreaterThanOrEqual<1, -5>;
1679
+ //=> true
1680
+
1681
+ type B = GreaterThanOrEqual<1, 1>;
1682
+ //=> true
1683
+
1684
+ type C = GreaterThanOrEqual<1, 5>;
1685
+ //=> false
1686
+ ```
1687
+
1688
+ Note: If either argument is the non-literal `number` type, the result is `boolean`.
1689
+
1690
+ @example
1691
+ ```
1692
+ import type {GreaterThanOrEqual} from 'type-fest';
1693
+
1694
+ type A = GreaterThanOrEqual<number, 1>;
1695
+ //=> boolean
1696
+
1697
+ type B = GreaterThanOrEqual<1, number>;
1698
+ //=> boolean
1699
+
1700
+ type C = GreaterThanOrEqual<number, number>;
1701
+ //=> boolean
1702
+ ```
1703
+
1704
+ @example
1705
+ ```
1706
+ import type {GreaterThanOrEqual} from 'type-fest';
1707
+
1708
+ // Use `GreaterThanOrEqual` to constrain a function parameter to non-negative numbers.
1709
+ declare function setNonNegative<N extends number>(value: GreaterThanOrEqual<N, 0> extends true ? N : never): void;
1710
+
1711
+ setNonNegative(0); // ✅ Allowed
1712
+ setNonNegative(1); // ✅ Allowed
1713
+
1714
+ // @ts-expect-error
1715
+ setNonNegative(-1);
1716
+
1717
+ // @ts-expect-error
1718
+ setNonNegative(-2);
1719
+ ```
1720
+ */
1721
+ type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? boolean : A extends number // For distributing `A`
1722
+ ? B extends number // For distributing `B`
1723
+ ? A extends B ? true : GreaterThan<A, B> : never // Should never happen
1724
+ : never; // Should never happen
1725
+ /**
1726
+ Returns a boolean for whether a given number is less than another number.
1727
+
1728
+ @example
1729
+ ```
1730
+ import type {LessThan} from 'type-fest';
1731
+
1732
+ type A = LessThan<1, -5>;
1733
+ //=> false
1734
+
1735
+ type B = LessThan<1, 1>;
1736
+ //=> false
1737
+
1738
+ type C = LessThan<1, 5>;
1739
+ //=> true
1740
+ ```
1741
+
1742
+ Note: If either argument is the non-literal `number` type, the result is `boolean`.
1743
+
1744
+ @example
1745
+ ```
1746
+ import type {LessThan} from 'type-fest';
1747
+
1748
+ type A = LessThan<number, 1>;
1749
+ //=> boolean
1750
+
1751
+ type B = LessThan<1, number>;
1752
+ //=> boolean
1753
+
1754
+ type C = LessThan<number, number>;
1755
+ //=> boolean
1756
+ ```
1757
+
1758
+ @example
1759
+ ```
1760
+ import type {LessThan} from 'type-fest';
1761
+
1762
+ // Use `LessThan` to constrain a function parameter to negative numbers.
1763
+ declare function setNegative<N extends number>(value: LessThan<N, 0> extends true ? N : never): void;
1764
+
1765
+ setNegative(-1); // ✅ Allowed
1766
+ setNegative(-2); // ✅ Allowed
1767
+
1768
+ // @ts-expect-error
1769
+ setNegative(0);
1770
+
1771
+ // @ts-expect-error
1772
+ setNegative(1);
1773
+ ```
1774
+ */
1775
+ type LessThan<A extends number, B extends number> = GreaterThanOrEqual<A, B> extends (infer Result) ? Result extends true ? false : true : never; // Should never happen
1776
+ /**
1777
+ Returns the maximum value from a tuple of integers.
1778
+
1779
+ Note:
1780
+ - Float numbers are not supported.
1781
+
1782
+ @example
1783
+ ```
1784
+ type A = TupleMax<[1, 2, 5, 3]>;
1785
+ //=> 5
1786
+
1787
+ type B = TupleMax<[1, 2, 5, 3, 99, -1]>;
1788
+ //=> 99
1789
+ ```
1790
+ */
1791
+ type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number] ? never : A extends [infer F extends number, ...infer R extends number[]] ? GreaterThan<F, Result> extends true ? TupleMax<R, F> : TupleMax<R, Result> : Result;
1792
+ /**
1793
+ Returns the difference between two numbers.
1794
+
1795
+ Note:
1796
+ - A or B can only support `-999` ~ `999`.
1797
+
1798
+ @example
1799
+ ```
1800
+ import type {Subtract, PositiveInfinity} from 'type-fest';
1801
+
1802
+ type A = Subtract<333, 222>;
1803
+ //=> 111
1804
+
1805
+ type B = Subtract<111, -222>;
1806
+ //=> 333
1807
+
1808
+ type C = Subtract<-111, 222>;
1809
+ //=> -333
1810
+
1811
+ type D = Subtract<18, 96>;
1812
+ //=> -78
1813
+
1814
+ type E = Subtract<PositiveInfinity, 9999>;
1815
+ //=> Infinity
1816
+
1817
+ type F = Subtract<PositiveInfinity, PositiveInfinity>;
1818
+ //=> number
1819
+ ```
1820
+
1821
+ @category Numeric
1822
+ */
1823
+ // TODO: Support big integer.
1824
+ type Subtract<A extends number, B extends number> =
1825
+ // Handle cases when A or B is the actual "number" type
1826
+ number extends A | B ? number :
1827
+ // Handle cases when A and B are both +/- infinity
1828
+ A extends B & (PositiveInfinity | NegativeInfinity) ? number :
1829
+ // Handle cases when A is - infinity or B is + infinity
1830
+ A extends NegativeInfinity ? NegativeInfinity : B extends PositiveInfinity ? NegativeInfinity :
1831
+ // Handle cases when A is + infinity or B is - infinity
1832
+ A extends PositiveInfinity ? PositiveInfinity : B extends NegativeInfinity ? PositiveInfinity :
1833
+ // Handle case when numbers are equal to each other
1834
+ A extends B ? 0 :
1835
+ // Handle cases when A or B is 0
1836
+ A extends 0 ? ReverseSign<B> : B extends 0 ? A :
1837
+ // Handle remaining regular cases
1838
+ SubtractPostChecks<A, B>;
1839
+ /**
1840
+ Subtracts two numbers A and B, such that they are not equal and neither of them are 0, +/- infinity or the `number` type
1841
+ */
1842
+ type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNegative<A>, IsNegative<B>]> = AreNegative extends [false, false] ? SubtractPositives<A, B> : AreNegative extends [true, true] ?
1843
+ // When both numbers are negative we subtract the absolute values and then reverse the sign
1844
+ ReverseSign<SubtractPositives<Absolute<A>, Absolute<B>>> :
1845
+ // When the signs are different we can add the absolute values and then reverse the sign if A < B
1846
+ [...TupleOf<Absolute<A>>, ...TupleOf<Absolute<B>>] extends (infer R extends unknown[]) ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length'] : never;
1847
+ /**
1848
+ Subtracts two positive numbers.
1849
+ */
1850
+ type SubtractPositives<A extends number, B extends number> = LessThan<A, B> extends true ?
1851
+ // When A < B we can reverse the result of B - A
1852
+ ReverseSign<SubtractIfAGreaterThanB<B, A>> : SubtractIfAGreaterThanB<A, B>;
1853
+ /**
1854
+ Subtracts two positive numbers A and B such that A > B.
1855
+ */
1856
+ type SubtractIfAGreaterThanB<A extends number, B extends number> =
1857
+ // This is where we always want to end up and do the actual subtraction
1858
+ TupleOf<A> extends [...TupleOf<B>, ...infer R] ? R['length'] : never;
1859
+ /**
1860
+ Returns the sum of two numbers.
1861
+
1862
+ Note:
1863
+ - A or B can only support `-999` ~ `999`.
1864
+
1865
+ @example
1866
+ ```
1867
+ import type {Sum, PositiveInfinity, NegativeInfinity} from 'type-fest';
1868
+
1869
+ type A = Sum<111, 222>;
1870
+ //=> 333
1871
+
1872
+ type B = Sum<-111, 222>;
1873
+ //=> 111
1874
+
1875
+ type C = Sum<111, -222>;
1876
+ //=> -111
1877
+
1878
+ type D = Sum<PositiveInfinity, -9999>;
1879
+ //=> Infinity
1880
+
1881
+ type E = Sum<PositiveInfinity, NegativeInfinity>;
1882
+ //=> number
1883
+ ```
1884
+
1885
+ @category Numeric
1886
+ */
1887
+ // TODO: Support big integer.
1888
+ type Sum<A extends number, B extends number> =
1889
+ // Handle cases when A or B is the actual "number" type
1890
+ number extends A | B ? number :
1891
+ // Handle cases when A and B are both +/- infinity
1892
+ A extends B & (PositiveInfinity | NegativeInfinity) ? A // A or B could be used here as they are equal
1893
+ :
1894
+ // Handle cases when A and B are opposite infinities
1895
+ A | B extends PositiveInfinity | NegativeInfinity ? number :
1896
+ // Handle cases when A is +/- infinity
1897
+ A extends PositiveInfinity | NegativeInfinity ? A :
1898
+ // Handle cases when B is +/- infinity
1899
+ B extends PositiveInfinity | NegativeInfinity ? B :
1900
+ // Handle cases when A or B is 0 or it's the same number with different signs
1901
+ A extends 0 ? B : B extends 0 ? A : A extends ReverseSign<B> ? 0 :
1902
+ // Handle remaining regular cases
1903
+ SumPostChecks<A, B>;
1904
+ /**
1905
+ Adds two numbers A and B, such that they are not equal with different signs and neither of them are 0, +/- infinity or the `number` type
1906
+ */
1907
+ type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative<A>, IsNegative<B>]> = AreNegative extends [false, false] ?
1908
+ // When both numbers are positive we can add them together
1909
+ SumPositives<A, B> : AreNegative extends [true, true] ?
1910
+ // When both numbers are negative we add the absolute values and then reverse the sign
1911
+ ReverseSign<SumPositives<Absolute<A>, Absolute<B>>> :
1912
+ // When the signs are different we can subtract the absolute values, remove the sign
1913
+ // and then reverse the sign if the larger absolute value is negative
1914
+ Absolute<Subtract<Absolute<A>, Absolute<B>>> extends (infer Result extends number) ? TupleMax<[Absolute<A>, Absolute<B>]> extends (infer Max_ extends number) ? Max_ extends A | B ?
1915
+ // The larger absolute value is positive, so the result is positive
1916
+ Result :
1917
+ // The larger absolute value is negative, so the result is negative
1918
+ ReverseSign<Result> : never : never;
1919
+ /**
1920
+ Adds two positive numbers.
1921
+ */
1922
+ type SumPositives<A extends number, B extends number> = [...TupleOf<A>, ...TupleOf<B>]['length'] extends (infer Result extends number) ? Result : never;
1923
+ /**
1924
+ Paths options.
1925
+
1926
+ @see {@link Paths}
1927
+ */
1928
+ type PathsOptions = {
1929
+ /**
1930
+ The maximum depth to recurse when searching for paths. Range: 0 ~ 10.
1931
+
1932
+ @default 5
1933
+ */
1934
+ maxRecursionDepth?: number;
1935
+ /**
1936
+ Use bracket notation for array indices and numeric object keys.
1937
+
1938
+ @default false
1939
+
1940
+ @example
1941
+ ```
1942
+ import type {Paths} from 'type-fest';
1943
+
1944
+ type ArrayExample = {
1945
+ array: ['foo'];
1946
+ };
1947
+
1948
+ type A = Paths<ArrayExample, {bracketNotation: false}>;
1949
+ //=> 'array' | 'array.0'
1950
+
1951
+ type B = Paths<ArrayExample, {bracketNotation: true}>;
1952
+ //=> 'array' | 'array[0]'
1953
+ ```
1954
+
1955
+ @example
1956
+ ```
1957
+ import type {Paths} from 'type-fest';
1958
+
1959
+ type NumberKeyExample = {
1960
+ 1: ['foo'];
1961
+ };
1962
+
1963
+ type A = Paths<NumberKeyExample, {bracketNotation: false}>;
1964
+ //=> 1 | '1' | '1.0'
1965
+
1966
+ type B = Paths<NumberKeyExample, {bracketNotation: true}>;
1967
+ //=> '[1]' | '[1][0]'
1968
+ ```
1969
+ */
1970
+ bracketNotation?: boolean;
1971
+ /**
1972
+ Only include leaf paths in the output.
1973
+
1974
+ @default false
1975
+
1976
+ @example
1977
+ ```
1978
+ import type {Paths} from 'type-fest';
1979
+
1980
+ type Post = {
1981
+ id: number;
1982
+ author: {
1983
+ id: number;
1984
+ name: {
1985
+ first: string;
1986
+ last: string;
1987
+ };
1988
+ };
1989
+ };
1990
+
1991
+ type AllPaths = Paths<Post, {leavesOnly: false}>;
1992
+ //=> 'id' | 'author' | 'author.id' | 'author.name' | 'author.name.first' | 'author.name.last'
1993
+
1994
+ type LeafPaths = Paths<Post, {leavesOnly: true}>;
1995
+ //=> 'id' | 'author.id' | 'author.name.first' | 'author.name.last'
1996
+ ```
1997
+
1998
+ @example
1999
+ ```
2000
+ import type {Paths} from 'type-fest';
2001
+
2002
+ type ArrayExample = {
2003
+ array: Array<{foo: string}>;
2004
+ tuple: [string, {bar: string}];
2005
+ };
2006
+
2007
+ type AllPaths = Paths<ArrayExample, {leavesOnly: false}>;
2008
+ //=> 'array' | 'tuple' | `array.${number}` | `array.${number}.foo` | 'tuple.0' | 'tuple.1' | 'tuple.1.bar'
2009
+
2010
+ type LeafPaths = Paths<ArrayExample, {leavesOnly: true}>;
2011
+ //=> `array.${number}.foo` | 'tuple.0' | 'tuple.1.bar'
2012
+ ```
2013
+ */
2014
+ leavesOnly?: boolean;
2015
+ /**
2016
+ Only include paths at the specified depth. By default all paths up to {@link PathsOptions.maxRecursionDepth | `maxRecursionDepth`} are included.
2017
+
2018
+ Note: Depth starts at `0` for root properties.
2019
+
2020
+ @default number
2021
+
2022
+ @example
2023
+ ```
2024
+ import type {Paths} from 'type-fest';
2025
+
2026
+ type Post = {
2027
+ id: number;
2028
+ author: {
2029
+ id: number;
2030
+ name: {
2031
+ first: string;
2032
+ last: string;
2033
+ };
2034
+ };
2035
+ };
2036
+
2037
+ type DepthZero = Paths<Post, {depth: 0}>;
2038
+ //=> 'id' | 'author'
2039
+
2040
+ type DepthOne = Paths<Post, {depth: 1}>;
2041
+ //=> 'author.id' | 'author.name'
2042
+
2043
+ type DepthTwo = Paths<Post, {depth: 2}>;
2044
+ //=> 'author.name.first' | 'author.name.last'
2045
+
2046
+ type LeavesAtDepthOne = Paths<Post, {leavesOnly: true; depth: 1}>;
2047
+ //=> 'author.id'
2048
+ ```
2049
+ */
2050
+ depth?: number;
2051
+ };
2052
+ type DefaultPathsOptions = {
2053
+ maxRecursionDepth: 5;
2054
+ bracketNotation: false;
2055
+ leavesOnly: false;
2056
+ depth: number;
2057
+ };
2058
+ /**
2059
+ Generate a union of all possible paths to properties in the given object.
2060
+
2061
+ It also works with arrays.
2062
+
2063
+ Use-case: You want a type-safe way to access deeply nested properties in an object.
2064
+
2065
+ @example
2066
+ ```
2067
+ import type {Paths} from 'type-fest';
2068
+
2069
+ type Project = {
2070
+ filename: string;
2071
+ listA: string[];
2072
+ listB: [{filename: string}];
2073
+ folder: {
2074
+ subfolder: {
2075
+ filename: string;
2076
+ };
2077
+ };
2078
+ };
2079
+
2080
+ type ProjectPaths = Paths<Project>;
2081
+ //=> 'filename' | 'listA' | 'listB' | 'folder' | `listA.${number}` | 'listB.0' | 'listB.0.filename' | 'folder.subfolder' | 'folder.subfolder.filename'
2082
+
2083
+ declare function open<Path extends ProjectPaths>(path: Path): void;
2084
+
2085
+ open('filename'); // Pass
2086
+ open('folder.subfolder'); // Pass
2087
+ open('folder.subfolder.filename'); // Pass
2088
+ // @ts-expect-error
2089
+ open('foo'); // TypeError
2090
+
2091
+ // Also works with arrays
2092
+ open('listA.1'); // Pass
2093
+ open('listB.0'); // Pass
2094
+ // @ts-expect-error
2095
+ open('listB.1'); // TypeError. Because listB only has one element.
2096
+ ```
2097
+
2098
+ @category Object
2099
+ @category Array
2100
+ */
2101
+ type Paths<T, Options extends PathsOptions = {}> = _Paths<T, ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, Options>>;
2102
+ type _Paths<T, Options extends Required<PathsOptions>, CurrentDepth extends number = 0> = T extends NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray> ? never : IsAny<T> extends true ? never : T extends object ? InternalPaths<Required<T>, Options, CurrentDepth> : never;
2103
+ type InternalPaths<T, Options extends Required<PathsOptions>, CurrentDepth extends number> = { [Key in keyof T]: Key extends string | number // Limit `Key` to `string | number`
2104
+ ? (And<Options['bracketNotation'], IsNumberLike<Key>> extends true ? `[${Key}]` : CurrentDepth extends 0 ?
2105
+ // Return both `Key` and `ToString<Key>` because for number keys, like `1`, both `1` and `'1'` are valid keys.
2106
+ Key | ToString<Key> : `.${(Key | ToString<Key>)}`) extends (infer TransformedKey extends string | number) ? ((Options['leavesOnly'] extends true ? Options['maxRecursionDepth'] extends CurrentDepth ? TransformedKey : IsNever<T[Key]> extends true ? TransformedKey : T[Key] extends (infer Value // For distributing `T[Key]`
2107
+ ) ? (Value extends readonly [] | NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray> ? TransformedKey : IsNever<keyof Value> extends true // Check for empty object & `unknown`, because `keyof unknown` is `never`.
2108
+ ? TransformedKey : never) : never // Should never happen
2109
+ : TransformedKey) extends (infer _TransformedKey) ?
2110
+ // If `depth` is provided, the condition becomes truthy only when it matches `CurrentDepth`.
2111
+ // Otherwise, since `depth` defaults to `number`, the condition is always truthy, returning paths at all depths.
2112
+ CurrentDepth extends Options['depth'] ? _TransformedKey : never : never) |
2113
+ // Recursively generate paths for the current key
2114
+ (GreaterThan<Options['maxRecursionDepth'], CurrentDepth> extends true // Limit the depth to prevent infinite recursion
2115
+ ? `${TransformedKey}${_Paths<T[Key], Options, Sum<CurrentDepth, 1>> & (string | number)}` : never) : never : never; }[keyof T & (T extends UnknownArray ? number : unknown)];
2116
+ /**
2117
+ Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
2118
+
2119
+ Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
2120
+
2121
+ This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
2122
+
2123
+ @example
2124
+ ```
2125
+ import type {LiteralUnion} from 'type-fest';
2126
+
2127
+ // Before
2128
+
2129
+ type Pet = 'dog' | 'cat' | string;
2130
+
2131
+ const petWithoutAutocomplete: Pet = '';
2132
+ // Start typing in your TypeScript-enabled IDE.
2133
+ // You **will not** get auto-completion for `dog` and `cat` literals.
2134
+
2135
+ // After
2136
+
2137
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
2138
+
2139
+ const petWithAutoComplete: Pet2 = '';
2140
+ // You **will** get auto-completion for `dog` and `cat` literals.
2141
+ ```
2142
+
2143
+ @category Type
2144
+ */
2145
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
2146
+ declare namespace PackageJson$1 {
2147
+ /**
2148
+ A person who has been involved in creating or maintaining the package.
2149
+ */
2150
+ type Person = string | {
2151
+ name: string;
2152
+ url?: string;
2153
+ email?: string;
2154
+ };
2155
+ type BugsLocation = string | {
2156
+ /**
2157
+ The URL to the package's issue tracker.
2158
+ */
2159
+ url?: string;
2160
+ /**
2161
+ The email address to which issues should be reported.
2162
+ */
2163
+ email?: string;
2164
+ };
2165
+ type DirectoryLocations = {
2166
+ [directoryType: string]: JsonValue | undefined;
2167
+ /**
2168
+ Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder.
2169
+ */
2170
+ bin?: string;
2171
+ /**
2172
+ Location for Markdown files.
2173
+ */
2174
+ doc?: string;
2175
+ /**
2176
+ Location for example scripts.
2177
+ */
2178
+ example?: string;
2179
+ /**
2180
+ Location for the bulk of the library.
2181
+ */
2182
+ lib?: string;
2183
+ /**
2184
+ Location for man pages. Sugar to generate a `man` array by walking the folder.
2185
+ */
2186
+ man?: string;
2187
+ /**
2188
+ Location for test files.
2189
+ */
2190
+ test?: string;
2191
+ };
2192
+ type Scripts = {
2193
+ /**
2194
+ Run **before** the package is published (Also run on local `npm install` without any arguments).
2195
+ */
2196
+ prepublish?: string;
2197
+ /**
2198
+ Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`.
2199
+ */
2200
+ prepare?: string;
2201
+ /**
2202
+ Run **before** the package is prepared and packed, **only** on `npm publish`.
2203
+ */
2204
+ prepublishOnly?: string;
2205
+ /**
2206
+ Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies).
2207
+ */
2208
+ prepack?: string;
2209
+ /**
2210
+ Run **after** the tarball has been generated and moved to its final destination.
2211
+ */
2212
+ postpack?: string;
2213
+ /**
2214
+ Run **after** the package is published.
2215
+ */
2216
+ publish?: string;
2217
+ /**
2218
+ Run **after** the package is published.
2219
+ */
2220
+ postpublish?: string;
2221
+ /**
2222
+ Run **before** the package is installed.
2223
+ */
2224
+ preinstall?: string;
2225
+ /**
2226
+ Run **after** the package is installed.
2227
+ */
2228
+ install?: string;
2229
+ /**
2230
+ Run **after** the package is installed and after `install`.
2231
+ */
2232
+ postinstall?: string;
2233
+ /**
2234
+ Run **before** the package is uninstalled and before `uninstall`.
2235
+ */
2236
+ preuninstall?: string;
2237
+ /**
2238
+ Run **before** the package is uninstalled.
2239
+ */
2240
+ uninstall?: string;
2241
+ /**
2242
+ Run **after** the package is uninstalled.
2243
+ */
2244
+ postuninstall?: string;
2245
+ /**
2246
+ Run **before** bump the package version and before `version`.
2247
+ */
2248
+ preversion?: string;
2249
+ /**
2250
+ Run **before** bump the package version.
2251
+ */
2252
+ version?: string;
2253
+ /**
2254
+ Run **after** bump the package version.
2255
+ */
2256
+ postversion?: string;
2257
+ /**
2258
+ Run with the `npm test` command, before `test`.
2259
+ */
2260
+ pretest?: string;
2261
+ /**
2262
+ Run with the `npm test` command.
2263
+ */
2264
+ test?: string;
2265
+ /**
2266
+ Run with the `npm test` command, after `test`.
2267
+ */
2268
+ posttest?: string;
2269
+ /**
2270
+ Run with the `npm stop` command, before `stop`.
2271
+ */
2272
+ prestop?: string;
2273
+ /**
2274
+ Run with the `npm stop` command.
2275
+ */
2276
+ stop?: string;
2277
+ /**
2278
+ Run with the `npm stop` command, after `stop`.
2279
+ */
2280
+ poststop?: string;
2281
+ /**
2282
+ Run with the `npm start` command, before `start`.
2283
+ */
2284
+ prestart?: string;
2285
+ /**
2286
+ Run with the `npm start` command.
2287
+ */
2288
+ start?: string;
2289
+ /**
2290
+ Run with the `npm start` command, after `start`.
2291
+ */
2292
+ poststart?: string;
2293
+ /**
2294
+ Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
2295
+ */
2296
+ prerestart?: string;
2297
+ /**
2298
+ Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
2299
+ */
2300
+ restart?: string;
2301
+ /**
2302
+ Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided.
2303
+ */
2304
+ postrestart?: string;
2305
+ } & Partial<Record<string, string>>;
2306
+ /**
2307
+ Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
2308
+ */
2309
+ type Dependency = Partial<Record<string, string>>;
2310
+ /**
2311
+ Recursive map describing selective dependency version overrides supported by npm.
2312
+ */
2313
+ type DependencyOverrides = { [packageName in string]: string | undefined | DependencyOverrides; };
2314
+ /**
2315
+ Specifies requirements for development environment components such as operating systems, runtimes, or package managers. Used to ensure consistent development environments across the team.
2316
+ */
2317
+ type DevEngineDependency = {
2318
+ name: string;
2319
+ version?: string;
2320
+ onFail?: 'ignore' | 'warn' | 'error' | 'download';
2321
+ };
2322
+ /**
2323
+ A mapping of conditions and the paths to which they resolve.
2324
+ */
2325
+ type ExportConditions = {
2326
+ [condition: string]: Exports;
2327
+ };
2328
+ /**
2329
+ Entry points of a module, optionally with conditions and subpath exports.
2330
+ */
2331
+ type Exports = null | string | Array<string | ExportConditions> | ExportConditions;
2332
+ /**
2333
+ Import map entries of a module, optionally with conditions and subpath imports.
2334
+ */
2335
+ type Imports = {
2336
+ [key: `#${string}`]: Exports;
2337
+ };
2338
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2339
+ interface NonStandardEntryPoints {
2340
+ /**
2341
+ An ECMAScript module ID that is the primary entry point to the program.
2342
+ */
2343
+ module?: string;
2344
+ /**
2345
+ A module ID with untranspiled code that is the primary entry point to the program.
2346
+ */
2347
+ esnext?: string | {
2348
+ [moduleName: string]: string | undefined;
2349
+ main?: string;
2350
+ browser?: string;
2351
+ };
2352
+ /**
2353
+ A hint to JavaScript bundlers or component tools when packaging modules for client side use.
2354
+ */
2355
+ browser?: string | Partial<Record<string, string | false>>;
2356
+ /**
2357
+ Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
2358
+
2359
+ [Read more.](https://webpack.js.org/guides/tree-shaking/)
2360
+ */
2361
+ sideEffects?: boolean | string[];
2362
+ }
2363
+ type TypeScriptConfiguration = {
2364
+ /**
2365
+ Location of the bundled TypeScript declaration file.
2366
+ */
2367
+ types?: string;
2368
+ /**
2369
+ Version selection map of TypeScript.
2370
+ */
2371
+ typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
2372
+ /**
2373
+ Location of the bundled TypeScript declaration file. Alias of `types`.
2374
+ */
2375
+ typings?: string;
2376
+ };
2377
+ /**
2378
+ An alternative configuration for workspaces.
2379
+ */
2380
+ type WorkspaceConfig = {
2381
+ /**
2382
+ An array of workspace pattern strings which contain the workspace packages.
2383
+ */
2384
+ packages?: WorkspacePattern[];
2385
+ /**
2386
+ Designed to solve the problem of packages which break when their `node_modules` are moved to the root workspace directory - a process known as hoisting. For these packages, both within your workspace, and also some that have been installed via `node_modules`, it is important to have a mechanism for preventing the default Yarn workspace behavior. By adding workspace pattern strings here, Yarn will resume non-workspace behavior for any package which matches the defined patterns.
2387
+
2388
+ [Supported](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/) by Yarn.
2389
+ [Not supported](https://github.com/npm/rfcs/issues/287) by npm.
2390
+ */
2391
+ nohoist?: WorkspacePattern[];
2392
+ };
2393
+ /**
2394
+ A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
2395
+
2396
+ The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
2397
+
2398
+ @example
2399
+ `docs` → Include the docs directory and install its dependencies.
2400
+ `packages/*` → Include all nested directories within the packages directory, like `packages/cli` and `packages/core`.
2401
+ */
2402
+ type WorkspacePattern = string;
2403
+ type YarnConfiguration = {
2404
+ /**
2405
+ If your package only allows one version of a given dependency, and you’d like to enforce the same behavior as `yarn install --flat` on the command-line, set this to `true`.
2406
+
2407
+ Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an app), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line.
2408
+ */
2409
+ flat?: boolean;
2410
+ /**
2411
+ Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file.
2412
+ */
2413
+ resolutions?: Dependency;
2414
+ };
2415
+ type JSPMConfiguration = {
2416
+ /**
2417
+ JSPM configuration.
2418
+ */
2419
+ jspm?: PackageJson$1;
2420
+ };
2421
+ /**
2422
+ Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
2423
+ */
2424
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
2425
+ interface PackageJsonStandard {
2426
+ /**
2427
+ The name of the package.
2428
+ */
2429
+ name?: string;
2430
+ /**
2431
+ Package version, parseable by [`node-semver`](https://github.com/npm/node-semver).
2432
+ */
2433
+ version?: string;
2434
+ /**
2435
+ Package description, listed in `npm search`.
2436
+ */
2437
+ description?: string;
2438
+ /**
2439
+ Keywords associated with package, listed in `npm search`.
2440
+ */
2441
+ keywords?: string[];
2442
+ /**
2443
+ The URL to the package's homepage.
2444
+ */
2445
+ homepage?: LiteralUnion<'.', string>;
2446
+ /**
2447
+ The URL to the package's issue tracker and/or the email address to which issues should be reported.
2448
+ */
2449
+ bugs?: BugsLocation;
2450
+ /**
2451
+ The license for the package.
2452
+ */
2453
+ license?: string;
2454
+ /**
2455
+ The licenses for the package.
2456
+ */
2457
+ licenses?: Array<{
2458
+ type?: string;
2459
+ url?: string;
2460
+ }>;
2461
+ author?: Person;
2462
+ /**
2463
+ A list of people who contributed to the package.
2464
+ */
2465
+ contributors?: Person[];
2466
+ /**
2467
+ A list of people who maintain the package.
2468
+ */
2469
+ maintainers?: Person[];
2470
+ /**
2471
+ The files included in the package.
2472
+ */
2473
+ files?: string[];
2474
+ /**
2475
+ Resolution algorithm for importing ".js" files from the package's scope.
2476
+
2477
+ [Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
2478
+ */
2479
+ type?: 'module' | 'commonjs';
2480
+ /**
2481
+ The module ID that is the primary entry point to the program.
2482
+ */
2483
+ main?: string;
2484
+ /**
2485
+ Subpath exports to define entry points of the package.
2486
+
2487
+ [Read more.](https://nodejs.org/api/packages.html#subpath-exports)
2488
+ */
2489
+ exports?: Exports;
2490
+ /**
2491
+ Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
2492
+
2493
+ [Read more.](https://nodejs.org/api/packages.html#subpath-imports)
2494
+ */
2495
+ imports?: Imports;
2496
+ /**
2497
+ The executable files that should be installed into the `PATH`.
2498
+ */
2499
+ bin?: string | Partial<Record<string, string>>;
2500
+ /**
2501
+ Filenames to put in place for the `man` program to find.
2502
+ */
2503
+ man?: string | string[];
2504
+ /**
2505
+ Indicates the structure of the package.
2506
+ */
2507
+ directories?: DirectoryLocations;
2508
+ /**
2509
+ Location for the code repository.
2510
+ */
2511
+ repository?: string | {
2512
+ type: string;
2513
+ url: string;
2514
+ /**
2515
+ Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
2516
+
2517
+ [Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md)
2518
+ */
2519
+ directory?: string;
2520
+ };
2521
+ /**
2522
+ Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
2523
+ */
2524
+ scripts?: Scripts;
2525
+ /**
2526
+ Is used to set configuration parameters used in package scripts that persist across upgrades.
2527
+ */
2528
+ config?: JsonObject;
2529
+ /**
2530
+ The dependencies of the package.
2531
+ */
2532
+ dependencies?: Dependency;
2533
+ /**
2534
+ Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
2535
+ */
2536
+ devDependencies?: Dependency;
2537
+ /**
2538
+ Dependencies that are skipped if they fail to install.
2539
+ */
2540
+ optionalDependencies?: Dependency;
2541
+ /**
2542
+ Dependencies that will usually be required by the package user directly or via another dependency.
2543
+ */
2544
+ peerDependencies?: Dependency;
2545
+ /**
2546
+ Indicate peer dependencies that are optional.
2547
+ */
2548
+ peerDependenciesMeta?: Partial<Record<string, {
2549
+ optional: true;
2550
+ }>>;
2551
+ /**
2552
+ Package names that are bundled when the package is published.
2553
+ */
2554
+ bundledDependencies?: string[];
2555
+ /**
2556
+ Alias of `bundledDependencies`.
2557
+ */
2558
+ bundleDependencies?: string[];
2559
+ /**
2560
+ Overrides is used to support selective version overrides using npm, which lets you define custom package versions or ranges inside your dependencies.
2561
+ */
2562
+ overrides?: DependencyOverrides;
2563
+ /**
2564
+ Engines that this package runs on.
2565
+ */
2566
+ engines?: { [EngineName in LiteralUnion<'npm' | 'node', string>]?: string; };
2567
+ /**
2568
+ @deprecated
2569
+ */
2570
+ engineStrict?: boolean;
2571
+ /**
2572
+ Operating systems the module runs on.
2573
+ */
2574
+ os?: Array<LiteralUnion<'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' | '!aix' | '!darwin' | '!freebsd' | '!linux' | '!openbsd' | '!sunos' | '!win32', string>>;
2575
+ /**
2576
+ CPU architectures the module runs on.
2577
+ */
2578
+ cpu?: Array<LiteralUnion<'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | '!arm' | '!arm64' | '!ia32' | '!mips' | '!mipsel' | '!ppc' | '!ppc64' | '!s390' | '!s390x' | '!x32' | '!x64', string>>;
2579
+ /**
2580
+ Define the runtime and package manager for developing the current project.
2581
+ */
2582
+ devEngines?: {
2583
+ os?: DevEngineDependency | DevEngineDependency[];
2584
+ cpu?: DevEngineDependency | DevEngineDependency[];
2585
+ libc?: DevEngineDependency | DevEngineDependency[];
2586
+ runtime?: DevEngineDependency | DevEngineDependency[];
2587
+ packageManager?: DevEngineDependency | DevEngineDependency[];
2588
+ };
2589
+ /**
2590
+ If set to `true`, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.
2591
+
2592
+ @deprecated
2593
+ */
2594
+ preferGlobal?: boolean;
2595
+ /**
2596
+ If set to `true`, then npm will refuse to publish it.
2597
+ */
2598
+ private?: boolean;
2599
+ /**
2600
+ A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
2601
+ */
2602
+ publishConfig?: PublishConfig;
2603
+ /**
2604
+ Describes and notifies consumers of a package's monetary support information.
2605
+
2606
+ [Read more.](https://github.com/npm/rfcs/blob/main/implemented/0017-add-funding-support.md)
2607
+ */
2608
+ funding?: string | {
2609
+ /**
2610
+ The type of funding.
2611
+ */
2612
+ type?: LiteralUnion<'github' | 'opencollective' | 'patreon' | 'individual' | 'foundation' | 'corporation', string>;
2613
+ /**
2614
+ The URL to the funding page.
2615
+ */
2616
+ url: string;
2617
+ };
2618
+ /**
2619
+ Used to configure [npm workspaces](https://docs.npmjs.com/cli/using-npm/workspaces) / [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
2620
+
2621
+ Workspaces allow you to manage multiple packages within the same repository in such a way that you only need to run your install command once in order to install all of them in a single pass.
2622
+
2623
+ Please note that the top-level `private` property of `package.json` **must** be set to `true` in order to use workspaces.
2624
+ */
2625
+ workspaces?: WorkspacePattern[] | WorkspaceConfig;
2626
+ }
2627
+ /**
2628
+ Type for [`package.json` file used by the Node.js runtime](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions).
2629
+ */
2630
+ type NodeJsStandard = {
2631
+ /**
2632
+ Defines which package manager is expected to be used when working on the current project. It can set to any of the [supported package managers](https://nodejs.org/api/corepack.html#supported-package-managers), and will ensure that your teams use the exact same package manager versions without having to install anything else than Node.js.
2633
+
2634
+ __This field is currently experimental and needs to be opted-in; check the [Corepack](https://nodejs.org/api/corepack.html) page for details about the procedure.__
2635
+
2636
+ @example
2637
+ ```json
2638
+ {
2639
+ "packageManager": "<package manager name>@<version>"
2640
+ }
2641
+ ```
2642
+ */
2643
+ packageManager?: string;
2644
+ };
2645
+ type PublishConfig = {
2646
+ /**
2647
+ Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig).
2648
+ */
2649
+ [additionalProperties: string]: JsonValue | undefined;
2650
+ /**
2651
+ When publishing scoped packages, the access level defaults to restricted. If you want your scoped package to be publicly viewable (and installable) set `--access=public`. The only valid values for access are public and restricted. Unscoped packages always have an access level of public.
2652
+ */
2653
+ access?: 'public' | 'restricted';
2654
+ /**
2655
+ The base URL of the npm registry.
2656
+
2657
+ Default: `'https://registry.npmjs.org/'`
2658
+ */
2659
+ registry?: string;
2660
+ /**
2661
+ The tag to publish the package under.
2662
+
2663
+ Default: `'latest'`
2664
+ */
2665
+ tag?: string;
2666
+ };
2667
+ }
2668
+ /**
2669
+ Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
2670
+
2671
+ @category File
2672
+ */
2673
+ type PackageJson$1 = JsonObject & PackageJson$1.NodeJsStandard & PackageJson$1.PackageJsonStandard & PackageJson$1.NonStandardEntryPoints & PackageJson$1.TypeScriptConfiguration & PackageJson$1.YarnConfiguration & PackageJson$1.JSPMConfiguration;
2674
+ type NormalizedPackageJson = Package & PackageJson;
2675
+ type PackageJson = PackageJson$1;
2676
+ type Cache<T = unknown> = Map<string, T>;
2677
+ type EnsurePackagesOptions = {
2678
+ /** Configuration for user confirmation prompts when installing packages */
2679
+ confirm?: {
2680
+ /** Default value for the confirmation prompt */
2681
+ default?: boolean;
2682
+ /** Message to display in the confirmation prompt, or a function that receives packages array */
2683
+ message: string | ((packages: string[]) => string);
2684
+ /**
2685
+ * Theme configuration for the prompt interface.
2686
+ * @deprecated Not implemented — the readline-based prompt ignores this option and uses
2687
+ * fixed styling. It will be removed in a future major release. Kept loosely typed so the
2688
+ * published declarations don't depend on `@inquirer/core`, which consumers never install.
2689
+ * `object` rather than a string-keyed record, because an interface-typed theme has no
2690
+ * index signature and so cannot satisfy the record form.
2691
+ */
2692
+ theme?: object;
2693
+ /** Function to transform the boolean value for display */
2694
+ transformer?: (value: boolean) => string;
2695
+ };
2696
+ /** Current working directory for package operations */
2697
+ cwd?: URL | string;
2698
+ /** Whether to include regular dependencies in the operation */
2699
+ deps?: boolean;
2700
+ /** Whether to include development dependencies in the operation */
2701
+ devDeps?: boolean;
2702
+ /** Additional options for package installation (excluding cwd and dev which are handled separately) */
2703
+ installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
2704
+ /** Custom logger interface for warning messages */
2705
+ logger?: {
2706
+ warn: (message: string) => void;
2707
+ };
2708
+ /** Whether to include peer dependencies in the operation */
2709
+ peerDeps?: boolean;
2710
+ /** Whether to throw an error when warnings are logged instead of just logging them */
2711
+ throwOnWarn?: boolean;
2712
+ };
2713
+ type ReadOptions = {
2714
+ cache?: FindPackageJsonCache | boolean;
2715
+ ignoreWarnings?: (RegExp | string)[];
2716
+ json5?: boolean;
2717
+ resolveCatalogs?: boolean;
2718
+ strict?: boolean;
2719
+ yaml?: boolean;
2720
+ };
2721
+ type FindPackageJsonCache = Cache<NormalizedReadResult>;
2722
+ type NormalizedReadResult = {
2723
+ packageJson: NormalizedPackageJson;
2724
+ path: string;
2725
+ };
2726
+ /**
2727
+ * An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
2728
+ * @param cwd The current working directory.
2729
+ * @param options Configuration options including yaml, json5, and resolveCatalogs flags.
2730
+ * @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
2731
+ * The type of the returned promise is `Promise&lt;NormalizedReadResult>`.
2732
+ * @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
2733
+ */
2734
+ declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
2735
+ /**
2736
+ * A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
2737
+ * @param cwd The current working directory.
2738
+ * @param options Configuration options including yaml, json5, and resolveCatalogs flags.
2739
+ * @returns An object containing the parsed package data and the file path.
2740
+ * @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
2741
+ */
2742
+ declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
2743
+ /**
2744
+ * An asynchronous function to write the package.json file with the given data.
2745
+ * @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
2746
+ * @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
2747
+ * This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
2748
+ * `cwd` represents the current working directory. If not specified, the default working directory will be used.
2749
+ * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise&lt;void>`.
2750
+ */
2751
+ declare const writePackageJson: (data: PackageJson, options?: WriteJsonOptions & {
2752
+ cwd?: URL | string;
2753
+ }) => Promise<void>;
2754
+ declare const writePackageJsonSync: (data: PackageJson, options?: WriteJsonOptions & {
2755
+ cwd?: URL | string;
2756
+ }) => void;
2757
+ /**
2758
+ * Clears the module-level package.json file and parse caches.
2759
+ *
2760
+ * The caches populated by `findPackageJson[Sync]` / `parsePackageJson[Sync]` when
2761
+ * `cache: true` (and no custom cache is supplied) never expire on their own. Call this
2762
+ * to drop all cached reads — for example in long-running processes or tests that mutate
2763
+ * package files out of band.
2764
+ */
2765
+ declare const clearPackageJsonCache: () => void;
2766
+ /**
2767
+ * A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
2768
+ * @param packageFile
2769
+ * @param options
2770
+ * @param options.cache Cache for parsed results (only applies to file paths)
2771
+ * @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
2772
+ * @param options.resolveCatalogs Whether to resolve pnpm catalog references
2773
+ * @param options.strict Whether to throw errors on normalization warnings
2774
+ * @param options.yaml Whether to enable package.yaml parsing (default: true)
2775
+ * @param options.json5 Whether to enable package.json5 parsing (default: true)
2776
+ * @returns
2777
+ * @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
2778
+ */
2779
+ declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
2780
+ cache?: Cache<NormalizedPackageJson> | boolean;
2781
+ ignoreWarnings?: (RegExp | string)[];
2782
+ json5?: boolean;
2783
+ resolveCatalogs?: boolean;
2784
+ strict?: boolean;
2785
+ yaml?: boolean;
2786
+ }) => NormalizedPackageJson;
2787
+ /**
2788
+ * An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
2789
+ * @param packageFile
2790
+ * @param options
2791
+ * @param options.cache Cache for parsed results (only applies to file paths)
2792
+ * @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
2793
+ * @param options.strict Whether to throw errors on normalization warnings
2794
+ * @param options.resolveCatalogs Whether to resolve pnpm catalog references
2795
+ * @param options.yaml Whether to enable package.yaml parsing (default: true)
2796
+ * @param options.json5 Whether to enable package.json5 parsing (default: true)
2797
+ * @returns
2798
+ * @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
2799
+ */
2800
+ declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
2801
+ cache?: Cache<NormalizedPackageJson> | boolean;
2802
+ ignoreWarnings?: (RegExp | string)[];
2803
+ json5?: boolean;
2804
+ resolveCatalogs?: boolean;
2805
+ strict?: boolean;
2806
+ yaml?: boolean;
2807
+ }) => Promise<NormalizedPackageJson>;
2808
+ /**
2809
+ * An asynchronous function to get the value of a property from the package.json file.
2810
+ * @param packageJson
2811
+ * @param property
2812
+ * @param defaultValue
2813
+ * @returns
2814
+ */
2815
+ declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
2816
+ /**
2817
+ * An asynchronous function to check if a property exists in the package.json file.
2818
+ * @param packageJson
2819
+ * @param property
2820
+ * @returns
2821
+ */
2822
+ declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
2823
+ /**
2824
+ * An asynchronous function to check if any of the specified dependencies exist in the package.json file.
2825
+ * @param packageJson
2826
+ * @param arguments_
2827
+ * @param options
2828
+ * @param options.peerDeps Whether to include peer dependencies
2829
+ * @returns
2830
+ */
2831
+ declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
2832
+ peerDeps?: boolean;
2833
+ }) => boolean;
2834
+ /**
2835
+ * An asynchronous function to ensure that the specified packages are installed in the package.json file.
2836
+ * If the packages are not installed, the user will be prompted to install them.
2837
+ * If the user agrees, the packages will be installed.
2838
+ * If the user declines, the function will return without installing the packages.
2839
+ * If the user does not respond, the function will return without installing the packages.
2840
+ * @param packageJson
2841
+ * @param packages
2842
+ * @param installKey
2843
+ * @param options
2844
+ * @param options.deps Whether to include regular dependencies
2845
+ * @param options.devDeps Whether to include development dependencies
2846
+ * @param options.peerDeps Whether to include peer dependencies
2847
+ * @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
2848
+ * @param options.logger Whether to use a custom logger
2849
+ * @param options.confirm Whether to use a custom confirmation prompt
2850
+ * @param options.installPackage Whether to use a custom installation package
2851
+ * @param options.cwd Whether to use a custom current working directory
2852
+ * @param options.dev Whether to use a custom installation key
2853
+ * @returns
2854
+ */
2855
+ declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
2856
+ export { EnsurePackagesOptions as E, FindPackageJsonCache as F, NormalizedPackageJson as N, PackageJson as P, NormalizedReadResult as a, findPackageJsonSync as b, clearPackageJsonCache as c, hasPackageJsonProperty as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJsonSync as i, writePackageJsonSync as j, parsePackageJson as p, writePackageJson as w };