@regle/core 1.8.4 → 1.8.6

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.
@@ -23,8 +23,9 @@ type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
23
23
  //#endregion
24
24
  //#region src/types/utils/Array.types.d.ts
25
25
  type ArrayElement<T> = T extends Array<infer U> ? U : never;
26
+ type NonEmptyTuple<T> = [T, ...T[]] | T[];
26
27
  //#endregion
27
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/primitive.d.ts
28
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/primitive.d.ts
28
29
  /**
29
30
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
30
31
 
@@ -32,27 +33,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
32
33
  */
33
34
  type Primitive = null | undefined | string | number | boolean | symbol | bigint;
34
35
  //#endregion
35
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts
36
- declare global {
37
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
38
- interface SymbolConstructor {
39
- readonly observable: symbol;
40
- }
41
- }
42
-
43
- /**
44
- @remarks
45
- The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
46
- As well, some guidance on making an `Observable` to not include `closed` property.
47
- @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
48
- @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
49
- @see https://github.com/benlesh/symbol-observable#making-an-object-observable
50
-
51
- @category Observable
52
- */
53
-
54
- //#endregion
55
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/union-to-intersection.d.ts
36
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/union-to-intersection.d.ts
56
37
  /**
57
38
  Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
58
39
 
@@ -114,7 +95,7 @@ Union extends unknown
114
95
  // The `& Union` is to allow indexing by the resulting type
115
96
  ? Intersection & Union : never;
116
97
  //#endregion
117
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/empty-object.d.ts
98
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/empty-object.d.ts
118
99
  declare const emptyObjectSymbol: unique symbol;
119
100
 
120
101
  /**
@@ -146,7 +127,6 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
146
127
  type EmptyObject = {
147
128
  [emptyObjectSymbol]?: never;
148
129
  };
149
-
150
130
  /**
151
131
  Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
152
132
 
@@ -164,7 +144,81 @@ type Fail = IsEmptyObject<null>; //=> false
164
144
  */
165
145
  type IsEmptyObject<T> = T extends EmptyObject ? true : false;
166
146
  //#endregion
167
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/optional-keys-of.d.ts
147
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-any.d.ts
148
+ /**
149
+ Returns a boolean for whether the given type is `any`.
150
+
151
+ @link https://stackoverflow.com/a/49928360/1490091
152
+
153
+ Useful in type utilities, such as disallowing `any`s to be passed to a function.
154
+
155
+ @example
156
+ ```
157
+ import type {IsAny} from 'type-fest';
158
+
159
+ const typedObject = {a: 1, b: 2} as const;
160
+ const anyObject: any = {a: 1, b: 2};
161
+
162
+ function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
163
+ return obj[key];
164
+ }
165
+
166
+ const typedA = get(typedObject, 'a');
167
+ //=> 1
168
+
169
+ const anyA = get(anyObject, 'a');
170
+ //=> any
171
+ ```
172
+
173
+ @category Type Guard
174
+ @category Utilities
175
+ */
176
+ type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
177
+ //#endregion
178
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-optional-key-of.d.ts
179
+ /**
180
+ Returns a boolean for whether the given key is an optional key of type.
181
+
182
+ This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
183
+
184
+ @example
185
+ ```
186
+ import type {IsOptionalKeyOf} from 'type-fest';
187
+
188
+ interface User {
189
+ name: string;
190
+ surname: string;
191
+
192
+ luckyNumber?: number;
193
+ }
194
+
195
+ interface Admin {
196
+ name: string;
197
+ surname?: string;
198
+ }
199
+
200
+ type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
201
+ //=> true
202
+
203
+ type T2 = IsOptionalKeyOf<User, 'name'>;
204
+ //=> false
205
+
206
+ type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
207
+ //=> boolean
208
+
209
+ type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
210
+ //=> false
211
+
212
+ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
213
+ //=> boolean
214
+ ```
215
+
216
+ @category Type Guard
217
+ @category Utilities
218
+ */
219
+ 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;
220
+ //#endregion
221
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/optional-keys-of.d.ts
168
222
  /**
169
223
  Extract all optional keys from the given type.
170
224
 
@@ -198,11 +252,11 @@ const update2: UpdateOperation<User> = {
198
252
 
199
253
  @category Utilities
200
254
  */
201
- type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
202
- ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
203
- : never; // Should never happen
255
+ type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
256
+ ? (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`
257
+ : never;
204
258
  //#endregion
205
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/required-keys-of.d.ts
259
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/required-keys-of.d.ts
206
260
  /**
207
261
  Extract all required keys from the given type.
208
262
 
@@ -227,11 +281,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
227
281
 
228
282
  @category Utilities
229
283
  */
230
- type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
231
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never; // Should never happen
232
-
284
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
285
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
233
286
  //#endregion
234
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-never.d.ts
287
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-never.d.ts
235
288
  /**
236
289
  Returns a boolean for whether the given type is `never`.
237
290
 
@@ -275,124 +328,174 @@ endIfEqual('abc', '123');
275
328
  */
276
329
  type IsNever$1<T> = [T] extends [never] ? true : false;
277
330
  //#endregion
278
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-never.d.ts
331
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/if.d.ts
279
332
  /**
280
- An if-else-like type that resolves depending on whether the given type is `never`.
333
+ An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
334
+
335
+ Use-cases:
336
+ - 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'>`.
281
337
 
282
- @see {@link IsNever}
338
+ Note:
339
+ - 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'`.
340
+ - Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
283
341
 
284
342
  @example
285
343
  ```
286
- import type {IfNever} from 'type-fest';
344
+ import {If} from 'type-fest';
287
345
 
288
- type ShouldBeTrue = IfNever<never>;
289
- //=> true
346
+ type A = If<true, 'yes', 'no'>;
347
+ //=> 'yes'
290
348
 
291
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
292
- //=> 'bar'
293
- ```
349
+ type B = If<false, 'yes', 'no'>;
350
+ //=> 'no'
294
351
 
295
- @category Type Guard
296
- @category Utilities
297
- */
298
- type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever);
299
- //#endregion
300
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-any.d.ts
301
- // Can eventually be replaced with the built-in once this library supports
302
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
303
- type NoInfer<T> = T extends infer U ? U : never;
352
+ type C = If<boolean, 'yes', 'no'>;
353
+ //=> 'yes' | 'no'
304
354
 
305
- /**
306
- Returns a boolean for whether the given type is `any`.
355
+ type D = If<any, 'yes', 'no'>;
356
+ //=> 'yes' | 'no'
307
357
 
308
- @link https://stackoverflow.com/a/49928360/1490091
309
-
310
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
358
+ type E = If<never, 'yes', 'no'>;
359
+ //=> 'no'
360
+ ```
311
361
 
312
362
  @example
313
363
  ```
314
- import type {IsAny} from 'type-fest';
364
+ import {If, IsAny, IsNever} from 'type-fest';
315
365
 
316
- const typedObject = {a: 1, b: 2} as const;
317
- const anyObject: any = {a: 1, b: 2};
366
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
367
+ //=> 'not any'
318
368
 
319
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
320
- return obj[key];
321
- }
369
+ type B = If<IsNever<never>, 'is never', 'not never'>;
370
+ //=> 'is never'
371
+ ```
322
372
 
323
- const typedA = get(typedObject, 'a');
324
- //=> 1
373
+ @example
374
+ ```
375
+ import {If, IsEqual} from 'type-fest';
325
376
 
326
- const anyA = get(anyObject, 'a');
327
- //=> any
377
+ type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
378
+
379
+ type A = IfEqual<string, string, 'equal', 'not equal'>;
380
+ //=> 'equal'
381
+
382
+ type B = IfEqual<string, number, 'equal', 'not equal'>;
383
+ //=> 'not equal'
328
384
  ```
329
385
 
330
386
  @category Type Guard
331
387
  @category Utilities
332
388
  */
333
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
389
+ type If<Type extends boolean, IfBranch, ElseBranch> = IsNever$1<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
334
390
  //#endregion
335
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-equal.d.ts
391
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/internal/type.d.ts
336
392
  /**
337
- Returns a boolean for whether the two given types are equal.
393
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
394
+ */
395
+ type BuiltIns = Primitive | void | Date | RegExp;
396
+ /**
397
+ Test if the given function has multiple call signatures.
338
398
 
339
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
340
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
399
+ Needed to handle the case of a single call signature with properties.
341
400
 
342
- Use-cases:
343
- - If you want to make a conditional branch based on the result of a comparison of two types.
401
+ Multiple call signatures cannot currently be supported due to a TypeScript limitation.
402
+ @see https://github.com/microsoft/TypeScript/issues/29732
403
+ */
404
+ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
405
+ (...arguments_: infer A): unknown;
406
+ (...arguments_: infer B): unknown;
407
+ } ? B extends A ? A extends B ? false : true : true : false;
408
+ /**
409
+ An if-else-like type that resolves depending on whether the given type is `any` or `never`.
344
410
 
345
411
  @example
346
412
  ```
347
- import type {IsEqual} from 'type-fest';
413
+ // When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
414
+ type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
415
+ //=> 'VALID'
348
416
 
349
- // This type returns a boolean for whether the given array includes the given item.
350
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
351
- type Includes<Value extends readonly any[], Item> =
352
- Value extends readonly [Value[0], ...infer rest]
353
- ? IsEqual<Value[0], Item> extends true
354
- ? true
355
- : Includes<rest, Item>
356
- : false;
357
- ```
417
+ // When `T` is `any` => Returns `IfAny` branch
418
+ type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
419
+ //=> 'IS_ANY'
358
420
 
359
- @category Type Guard
360
- @category Utilities
421
+ // When `T` is `never` => Returns `IfNever` branch
422
+ type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
423
+ //=> 'IS_NEVER'
424
+ ```
361
425
  */
362
- type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
426
+ type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever$1<T>, IfNever, IfNotAnyOrNever>>;
363
427
  //#endregion
364
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/or.d.ts
428
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-null.d.ts
365
429
  /**
366
- Returns a boolean for whether either of two given types are true.
367
-
368
- Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
430
+ Returns a boolean for whether the given type is `null`.
369
431
 
370
432
  @example
371
433
  ```
372
- import type {Or} from 'type-fest';
434
+ import type {IsNull} from 'type-fest';
373
435
 
374
- Or<true, false>;
375
- //=> true
436
+ type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
376
437
 
377
- Or<false, false>;
378
- //=> false
438
+ type Example1 = NonNullFallback<null, string>;
439
+ //=> string
440
+
441
+ type Example2 = NonNullFallback<number, string>;
442
+ //=? number
379
443
  ```
380
444
 
381
- @see {@link And}
445
+ @category Type Guard
446
+ @category Utilities
382
447
  */
383
- type Or<A extends boolean, B extends boolean> = [A, B][number] extends false ? false : true extends [IsEqual<A, true>, IsEqual<B, true>][number] ? true : never;
448
+ type IsNull<T> = [T] extends [null] ? true : false;
384
449
  //#endregion
385
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/keys.d.ts
450
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-unknown.d.ts
386
451
  /**
387
- Disallows any of the given keys.
388
- */
389
- type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
452
+ Returns a boolean for whether the given type is `unknown`.
390
453
 
391
- /**
392
- Utility type to retrieve only literal keys from type.
454
+ @link https://github.com/dsherret/conditional-type-checks/pull/16
455
+
456
+ Useful in type utilities, such as when dealing with unknown data from API calls.
457
+
458
+ @example
459
+ ```
460
+ import type {IsUnknown} from 'type-fest';
461
+
462
+ // https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
463
+ type Action<TState, TPayload = void> =
464
+ IsUnknown<TPayload> extends true
465
+ ? (state: TState) => TState,
466
+ : (state: TState, payload: TPayload) => TState;
467
+
468
+ class Store<TState> {
469
+ constructor(private state: TState) {}
470
+
471
+ execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
472
+ this.state = action(this.state, payload);
473
+ return this.state;
474
+ }
475
+
476
+ // ... other methods
477
+ }
478
+
479
+ const store = new Store({value: 1});
480
+ declare const someExternalData: unknown;
481
+
482
+ store.execute(state => ({value: state.value + 1}));
483
+ //=> `TPayload` is `void`
484
+
485
+ store.execute((state, payload) => ({value: state.value + payload}), 5);
486
+ //=> `TPayload` is `5`
487
+
488
+ store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
489
+ //=> Errors: `action` is `(state: TState) => TState`
490
+ ```
491
+
492
+ @category Utilities
393
493
  */
494
+ type IsUnknown<T> = (unknown extends T // `T` can be `unknown` or `any`
495
+ ? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
496
+ ? true : false : false);
394
497
  //#endregion
395
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/simplify.d.ts
498
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/simplify.d.ts
396
499
  /**
397
500
  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.
398
501
 
@@ -452,7 +555,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
452
555
  */
453
556
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
454
557
  //#endregion
455
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/omit-index-signature.d.ts
558
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/omit-index-signature.d.ts
456
559
  /**
457
560
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
458
561
 
@@ -545,7 +648,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
545
648
  */
546
649
  type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
547
650
  //#endregion
548
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/pick-index-signature.d.ts
651
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/pick-index-signature.d.ts
549
652
  /**
550
653
  Pick only index signatures from the given object type, leaving out all explicitly defined properties.
551
654
 
@@ -593,7 +696,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
593
696
  */
594
697
  type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
595
698
  //#endregion
596
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/merge.d.ts
699
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/merge.d.ts
597
700
  // Merges two objects without worrying about index signatures.
598
701
  type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
599
702
 
@@ -633,101 +736,7 @@ export type FooBar = Merge<Foo, Bar>;
633
736
  */
634
737
  type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
635
738
  //#endregion
636
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-any.d.ts
637
- /**
638
- An if-else-like type that resolves depending on whether the given type is `any`.
639
-
640
- @see {@link IsAny}
641
-
642
- @example
643
- ```
644
- import type {IfAny} from 'type-fest';
645
-
646
- type ShouldBeTrue = IfAny<any>;
647
- //=> true
648
-
649
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
650
- //=> 'bar'
651
- ```
652
-
653
- @category Type Guard
654
- @category Utilities
655
- */
656
- type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
657
- //#endregion
658
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/type.d.ts
659
- /**
660
- Matches any primitive, `void`, `Date`, or `RegExp` value.
661
- */
662
- type BuiltIns = Primitive | void | Date | RegExp;
663
-
664
- /**
665
- Matches non-recursive types.
666
- */
667
-
668
- /**
669
- Test if the given function has multiple call signatures.
670
-
671
- Needed to handle the case of a single call signature with properties.
672
-
673
- Multiple call signatures cannot currently be supported due to a TypeScript limitation.
674
- @see https://github.com/microsoft/TypeScript/issues/29732
675
- */
676
- type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
677
- (...arguments_: infer A): unknown;
678
- (...arguments_: infer B): unknown;
679
- } ? B extends A ? A extends B ? false : true : true : false;
680
-
681
- /**
682
- Returns a boolean for whether the given `boolean` is not `false`.
683
- */
684
-
685
- /**
686
- Returns a boolean for whether the given type is a union type.
687
-
688
- @example
689
- ```
690
- type A = IsUnion<string | number>;
691
- //=> true
692
-
693
- type B = IsUnion<string>;
694
- //=> false
695
- ```
696
- */
697
- type IsUnion$1<T> = InternalIsUnion<T>;
698
-
699
- /**
700
- The actual implementation of `IsUnion`.
701
- */
702
- type InternalIsUnion<T, U = T> = (
703
- // @link https://ghaiklor.github.io/type-challenges-solutions/en/medium-isunion.html
704
- IsNever$1<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result
705
- // In some cases `Result` will return `false | true` which is `boolean`,
706
- // that means `T` has at least two types and it's a union type,
707
- // so we will return `true` instead of `boolean`.
708
- ? boolean extends Result ? true : Result : never; // Should never happen
709
-
710
- /**
711
- An if-else-like type that resolves depending on whether the given type is `any` or `never`.
712
-
713
- @example
714
- ```
715
- // When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
716
- type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
717
- //=> 'VALID'
718
-
719
- // When `T` is `any` => Returns `IfAny` branch
720
- type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
721
- //=> 'IS_ANY'
722
-
723
- // When `T` is `never` => Returns `IfNever` branch
724
- type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
725
- //=> 'IS_NEVER'
726
- ```
727
- */
728
- type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever$1<T> extends true ? IfNever : IfNotAnyOrNever;
729
- //#endregion
730
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/object.d.ts
739
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/internal/object.d.ts
731
740
  /**
732
741
  Merges user specified options with default options.
733
742
 
@@ -780,10 +789,95 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
780
789
  // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
781
790
  ```
782
791
  */
783
- type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
784
- >>;
792
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever$1<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
793
+ //#endregion
794
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/or.d.ts
795
+ /**
796
+ Returns a boolean for whether either of two given types are true.
797
+
798
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
799
+
800
+ @example
801
+ ```
802
+ import type {Or} from 'type-fest';
803
+
804
+ type TT = Or<true, false>;
805
+ //=> true
806
+
807
+ type TF = Or<true, false>;
808
+ //=> true
809
+
810
+ type FT = Or<false, true>;
811
+ //=> true
812
+
813
+ type FF = Or<false, false>;
814
+ //=> false
815
+ ```
816
+
817
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
818
+ For example, `And<false, boolean>` expands to `And<false, true> | And<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
819
+ @example
820
+ ```
821
+ import type {And} from 'type-fest';
822
+
823
+ type A = Or<false, boolean>;
824
+ //=> boolean
825
+
826
+ type B = Or<boolean, false>;
827
+ //=> boolean
828
+
829
+ type C = Or<true, boolean>;
830
+ //=> true
831
+
832
+ type D = Or<boolean, true>;
833
+ //=> true
834
+
835
+ type E = Or<boolean, boolean>;
836
+ //=> boolean
837
+ ```
838
+
839
+ Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
840
+
841
+ @example
842
+ ```
843
+ import type {Or} from 'type-fest';
844
+
845
+ type A = Or<true, never>;
846
+ //=> true
847
+
848
+ type B = Or<never, true>;
849
+ //=> true
850
+
851
+ type C = Or<false, never>;
852
+ //=> false
853
+
854
+ type D = Or<never, false>;
855
+ //=> false
856
+
857
+ type E = Or<boolean, never>;
858
+ //=> boolean
859
+
860
+ type F = Or<never, boolean>;
861
+ //=> boolean
862
+
863
+ type G = Or<never, never>;
864
+ //=> false
865
+ ```
866
+
867
+ @see {@link And}
868
+ */
869
+ type Or<A extends boolean, B extends boolean> = _Or<If<IsNever$1<A>, false, A>, If<IsNever$1<B>, false, B>>;
870
+ // `never` is treated as `false`
871
+
872
+ type _Or<A extends boolean, B extends boolean> = A extends true ? true : B extends true ? true : false;
873
+ //#endregion
874
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/internal/keys.d.ts
875
+ /**
876
+ Disallows any of the given keys.
877
+ */
878
+ type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
785
879
  //#endregion
786
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/require-exactly-one.d.ts
880
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/require-exactly-one.d.ts
787
881
  /**
788
882
  Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
789
883
 
@@ -813,10 +907,10 @@ const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
813
907
 
814
908
  @category Object
815
909
  */
816
- type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, never, _RequireExactlyOne<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
910
+ type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever$1<KeysType>, never, _RequireExactlyOne<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
817
911
  type _RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]: (Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>) }[KeysType] & Omit<ObjectType, KeysType>;
818
912
  //#endregion
819
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/require-one-or-none.d.ts
913
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/require-one-or-none.d.ts
820
914
  /**
821
915
  Create a type that requires exactly one of the given keys and disallows more, or none of the given keys. The remaining keys are kept as is.
822
916
 
@@ -847,10 +941,35 @@ const responder3: Responder = {
847
941
 
848
942
  @category Object
849
943
  */
850
- type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, ObjectType, _RequireOneOrNone<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
944
+ type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever$1<KeysType>, ObjectType, _RequireOneOrNone<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
851
945
  type _RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
852
946
  //#endregion
853
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/partial-deep.d.ts
947
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-union.d.ts
948
+ /**
949
+ Returns a boolean for whether the given type is a union.
950
+
951
+ @example
952
+ ```
953
+ import type {IsUnion} from 'type-fest';
954
+
955
+ type A = IsUnion<string | number>;
956
+ //=> true
957
+
958
+ type B = IsUnion<string>;
959
+ //=> false
960
+ ```
961
+ */
962
+ type IsUnion$1<T> = InternalIsUnion<T>;
963
+ /**
964
+ The actual implementation of `IsUnion`.
965
+ */
966
+ type InternalIsUnion<T, U = T> = (IsNever$1<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result
967
+ // In some cases `Result` will return `false | true` which is `boolean`,
968
+ // that means `T` has at least two types and it's a union type,
969
+ // so we will return `true` instead of `boolean`.
970
+ ? boolean extends Result ? true : Result : never; // Should never happen
971
+ //#endregion
972
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/partial-deep.d.ts
854
973
  /**
855
974
  @see {@link PartialDeep}
856
975
  */
@@ -865,24 +984,23 @@ type PartialDeepOptions = {
865
984
  Allows `undefined` values in non-tuple arrays.
866
985
  - When set to `true`, elements of non-tuple arrays can be `undefined`.
867
986
  - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
868
- @default true
987
+ @default false
869
988
  @example
870
- You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
989
+ You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
871
990
  ```
872
991
  import type {PartialDeep} from 'type-fest';
873
992
  type Settings = {
874
993
  languages: string[];
875
994
  };
876
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
877
- partialSettings.languages = [undefined]; // Error
878
- partialSettings.languages = []; // Ok
995
+ declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
996
+ partialSettings.languages = [undefined]; // OK
879
997
  ```
880
998
  */
881
999
  readonly allowUndefinedInNonTupleArrays?: boolean;
882
1000
  };
883
1001
  type DefaultPartialDeepOptions = {
884
1002
  recurseIntoArrays: false;
885
- allowUndefinedInNonTupleArrays: true;
1003
+ allowUndefinedInNonTupleArrays: false;
886
1004
  };
887
1005
 
888
1006
  /**
@@ -896,19 +1014,19 @@ Use-cases:
896
1014
  ```
897
1015
  import type {PartialDeep} from 'type-fest';
898
1016
 
899
- const settings: Settings = {
1017
+ let settings = {
900
1018
  textEditor: {
901
1019
  fontSize: 14,
902
1020
  fontColor: '#000000',
903
- fontWeight: 400
1021
+ fontWeight: 400,
904
1022
  },
905
1023
  autocomplete: false,
906
- autosave: true
1024
+ autosave: true,
907
1025
  };
908
1026
 
909
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
910
- return {...settings, ...savedSettings};
911
- }
1027
+ const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
1028
+ {...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
1029
+ );
912
1030
 
913
1031
  settings = applySavedSettings({textEditor: {fontWeight: 500}});
914
1032
  ```
@@ -918,13 +1036,15 @@ By default, this does not affect elements in array and tuple types. You can chan
918
1036
  ```
919
1037
  import type {PartialDeep} from 'type-fest';
920
1038
 
921
- type Settings = {
922
- languages: string[];
923
- }
1039
+ type Shape = {
1040
+ dimensions: [number, number];
1041
+ };
924
1042
 
925
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
926
- languages: [undefined]
1043
+ const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
1044
+ dimensions: [], // OK
927
1045
  };
1046
+
1047
+ partialShape.dimensions = [15]; // OK
928
1048
  ```
929
1049
 
930
1050
  @see {@link PartialDeepOptions}
@@ -968,9 +1088,7 @@ Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for
968
1088
  */
969
1089
  type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = (ObjectType extends ((...arguments_: any) => unknown) ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType> : {}) & ({ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> });
970
1090
  //#endregion
971
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/required-deep.d.ts
972
- type ExcludeUndefined<T> = Exclude<T, undefined>;
973
-
1091
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/required-deep.d.ts
974
1092
  /**
975
1093
  Create a type from another type with all keys and nested keys set to required.
976
1094
 
@@ -984,23 +1102,23 @@ import type {RequiredDeep} from 'type-fest';
984
1102
 
985
1103
  type Settings = {
986
1104
  textEditor?: {
987
- fontSize?: number | undefined;
988
- fontColor?: string | undefined;
1105
+ fontSize?: number;
1106
+ fontColor?: string;
989
1107
  fontWeight?: number | undefined;
990
- }
991
- autocomplete?: boolean | undefined;
1108
+ };
1109
+ autocomplete?: boolean;
992
1110
  autosave?: boolean | undefined;
993
1111
  };
994
1112
 
995
1113
  type RequiredSettings = RequiredDeep<Settings>;
996
- // type RequiredSettings = {
1114
+ //=> {
997
1115
  // textEditor: {
998
1116
  // fontSize: number;
999
1117
  // fontColor: string;
1000
- // fontWeight: number;
1001
- // }
1118
+ // fontWeight: number | undefined;
1119
+ // };
1002
1120
  // autocomplete: boolean;
1003
- // autosave: boolean;
1121
+ // autosave: boolean | undefined;
1004
1122
  // }
1005
1123
  ```
1006
1124
 
@@ -1012,14 +1130,10 @@ Note that types containing overloaded functions are not made deeply required due
1012
1130
  @category Set
1013
1131
  @category Map
1014
1132
  */
1015
- type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns ? E : E extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : E extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : E extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : E extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : E extends ((...arguments_: any[]) => unknown) ? {} extends RequiredObjectDeep<E> ? E : HasMultipleCallSignatures<E> extends true ? E : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E> : E extends object ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
1016
- ? ItemType[] extends E // Test for arrays (non-tuples) specifically
1017
- ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
1018
- : RequiredObjectDeep<E> // Tuples behave properly
1019
- : RequiredObjectDeep<E> : unknown;
1133
+ type RequiredDeep<T> = T extends BuiltIns ? T : T extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : T extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : T extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : T extends ((...arguments_: any[]) => unknown) ? {} extends RequiredObjectDeep<T> ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & RequiredObjectDeep<T> : T extends object ? RequiredObjectDeep<T> : unknown;
1020
1134
  type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
1021
1135
  //#endregion
1022
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/union-to-tuple.d.ts
1136
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/union-to-tuple.d.ts
1023
1137
  /**
1024
1138
  Returns the last element of a union type.
1025
1139
 
@@ -1068,76 +1182,6 @@ const petList = Object.keys(pets) as UnionToTuple<Pet>;
1068
1182
  */
1069
1183
  type UnionToTuple<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
1070
1184
  //#endregion
1071
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-null.d.ts
1072
- /**
1073
- Returns a boolean for whether the given type is `null`.
1074
-
1075
- @example
1076
- ```
1077
- import type {IsNull} from 'type-fest';
1078
-
1079
- type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
1080
-
1081
- type Example1 = NonNullFallback<null, string>;
1082
- //=> string
1083
-
1084
- type Example2 = NonNullFallback<number, string>;
1085
- //=? number
1086
- ```
1087
-
1088
- @category Type Guard
1089
- @category Utilities
1090
- */
1091
- type IsNull<T> = [T] extends [null] ? true : false;
1092
- //#endregion
1093
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-unknown.d.ts
1094
- /**
1095
- Returns a boolean for whether the given type is `unknown`.
1096
-
1097
- @link https://github.com/dsherret/conditional-type-checks/pull/16
1098
-
1099
- Useful in type utilities, such as when dealing with unknown data from API calls.
1100
-
1101
- @example
1102
- ```
1103
- import type {IsUnknown} from 'type-fest';
1104
-
1105
- // https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
1106
- type Action<TState, TPayload = void> =
1107
- IsUnknown<TPayload> extends true
1108
- ? (state: TState) => TState,
1109
- : (state: TState, payload: TPayload) => TState;
1110
-
1111
- class Store<TState> {
1112
- constructor(private state: TState) {}
1113
-
1114
- execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
1115
- this.state = action(this.state, payload);
1116
- return this.state;
1117
- }
1118
-
1119
- // ... other methods
1120
- }
1121
-
1122
- const store = new Store({value: 1});
1123
- declare const someExternalData: unknown;
1124
-
1125
- store.execute(state => ({value: state.value + 1}));
1126
- //=> `TPayload` is `void`
1127
-
1128
- store.execute((state, payload) => ({value: state.value + payload}), 5);
1129
- //=> `TPayload` is `5`
1130
-
1131
- store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
1132
- //=> Errors: `action` is `(state: TState) => TState`
1133
- ```
1134
-
1135
- @category Utilities
1136
- */
1137
- type IsUnknown<T> = (unknown extends T // `T` can be `unknown` or `any`
1138
- ? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
1139
- ? true : false : false);
1140
- //#endregion
1141
1185
  //#region src/types/core/modifiers.types.d.ts
1142
1186
  interface RegleBehaviourOptions {
1143
1187
  /**
@@ -1332,30 +1376,16 @@ type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | u
1332
1376
  * Negates a boolean type.
1333
1377
  */
1334
1378
  type Not<T extends boolean> = T extends true ? false : true;
1335
- /**
1336
- * Returns `true` if at least one of the types in the
1337
- * {@linkcode Types} array is `true`, otherwise returns `false`.
1338
- */
1339
-
1340
1379
  /**
1341
1380
  * Checks if the given type is `never`.
1342
1381
  */
1343
1382
  type IsNever<T> = [T] extends [never] ? true : false;
1344
- /**
1345
- * Checks if the given type is `any`.
1346
- */
1347
-
1348
1383
  /**
1349
1384
  * Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
1350
1385
  * 1. If either type is `never`, the result is `true` iff the other type is also `never`.
1351
1386
  * 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
1352
1387
  */
1353
1388
  type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
1354
- /**
1355
- * Checks if the {@linkcode Left} type extends the {@linkcode Right} type,
1356
- * excluding `any` or `never`.
1357
- */
1358
-
1359
1389
  /**
1360
1390
  * Convert a union to an intersection.
1361
1391
  * `A | B | C` -\> `A & B & C`
@@ -1378,17 +1408,6 @@ type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends t
1378
1408
  */
1379
1409
  type UnionToTuple$1<Union> = TuplifyUnion<Union>;
1380
1410
  type IsUnion<T> = Not<Extends<UnionToTuple$1<T>['length'], 1>>;
1381
- /**
1382
- * A recursive version of `Pick` that selects properties from the left type that are present in the right type.
1383
- * The "leaf" types from `Left` are used - only the keys of `Right` are considered.
1384
- *
1385
- * @example
1386
- * ```ts
1387
- * const user = {email: 'a@b.com', name: 'John Doe', address: {street: '123 2nd St', city: 'New York', zip: '10001', state: 'NY', country: 'USA'}}
1388
- *
1389
- * type Result = DeepPickMatchingProps<typeof user, {name: unknown; address: {city: unknown}}> // {name: string, address: {city: string}}
1390
- * ```
1391
- */
1392
1411
  //#endregion
1393
1412
  //#region src/types/core/variants.types.d.ts
1394
1413
  type NarrowVariant<TRoot extends {
@@ -1631,7 +1650,7 @@ type IsLiteral<T> = string extends T ? false : true;
1631
1650
  /**
1632
1651
  * Returned typed of rules created with `createRule`
1633
1652
  * */
1634
- interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & infer M ? M : TValue)> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
1653
+ interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, _TInput = unknown, TFilteredValue extends any = (TValue extends Date & File & infer M ? M : TValue)> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
1635
1654
  validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
1636
1655
  message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
1637
1656
  active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
@@ -1640,10 +1659,6 @@ interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends
1640
1659
  _value?: IsLiteral<TValue> extends true ? TValue : any;
1641
1660
  exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
1642
1661
  }
1643
- /**
1644
- * @internal
1645
- * */
1646
-
1647
1662
  /**
1648
1663
  * Rules with params created with `createRules` are callable while being customizable
1649
1664
  */
@@ -1687,10 +1702,6 @@ type PossibleRegleRuleMetadataConsumer<TValue> = {
1687
1702
  } & DefaultMetadataProperties & {
1688
1703
  $params?: [...any[]];
1689
1704
  };
1690
- /**
1691
- * @internal
1692
- */
1693
-
1694
1705
  /**
1695
1706
  * Generic types for a created RegleRule
1696
1707
  */
@@ -1740,11 +1751,6 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
1740
1751
  type?: string;
1741
1752
  async?: boolean;
1742
1753
  }
1743
- /**
1744
- * @internal
1745
- * createRule arguments options
1746
- */
1747
-
1748
1754
  type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
1749
1755
  value: TValue;
1750
1756
  params: [...TParams];
@@ -1894,10 +1900,6 @@ type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
1894
1900
  * @public
1895
1901
  */
1896
1902
  type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
1897
- /**
1898
- * @internal
1899
- */
1900
-
1901
1903
  /**
1902
1904
  * @public
1903
1905
  * Regroup inline and registered rules
@@ -2336,11 +2338,6 @@ declare function createRule<TValue extends any, TParams extends any[], TReturn e
2336
2338
  * Removing Ref and executing function to return the unwrapped value
2337
2339
  */
2338
2340
  declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
2339
- /**
2340
- * Returns a clean list of parameters
2341
- * Removing Ref and executing function to return the unwrapped value
2342
- */
2343
-
2344
2341
  //#endregion
2345
2342
  //#region src/core/defineRegleConfig.d.ts
2346
2343
  /**
@@ -2460,7 +2457,9 @@ type CreateScopedUseRegleOptions<TCustomRegle extends useRegleFn<any, any>, TAsR
2460
2457
  */
2461
2458
  customStore?: Ref<ScopedInstancesRecordLike>;
2462
2459
  /**
2463
- * Set the
2460
+ * Collect instances in a Record instead of an array
2461
+ *
2462
+ * ⚠️ Each nested `useScopedRegle` must provide a parameter `scopeKey` to be collected.
2464
2463
  */
2465
2464
  asRecord?: TAsRecord;
2466
2465
  };
@@ -2516,9 +2515,14 @@ declare function createVariant<TForm extends Record<string, any>, TDiscriminant
2516
2515
  */
2517
2516
  declare function narrowVariant<TRoot extends {
2518
2517
  [x: string]: unknown;
2518
+ $fields: {
2519
+ [x: string]: unknown;
2520
+ };
2519
2521
  }, const TKey extends keyof TRoot, const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
2520
2522
  $value: infer V;
2521
- } ? V : unknown)>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }>;
2523
+ } ? V : unknown)>(root: TRoot, discriminantKey: TKey, discriminantValue: TValue): root is Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }> & {
2524
+ $fields: Extract<TRoot['$fields'], { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }>;
2525
+ };
2522
2526
  /**
2523
2527
  * Narrow a nested variant root to a reactive reference
2524
2528
  *
@@ -2530,7 +2534,9 @@ declare function narrowVariant<TRoot extends {
2530
2534
  */
2531
2535
  declare function variantToRef<TRoot extends RegleStatus<{}, any, any>, const TKey extends keyof TRoot['$fields'], const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot['$fields'][TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
2532
2536
  $value: infer V;
2533
- } ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue): Ref<Extract<TRoot['$fields'], { [K in TKey]: RegleFieldStatus<TValue, any, any> }> | undefined>;
2537
+ } ? V : unknown)>(root: MaybeRef<TRoot>, discriminantKey: TKey, discriminantValue: TValue): Ref<(Extract<TRoot, { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }> & {
2538
+ $fields: Extract<TRoot['$fields'], { [K in TKey]: RegleFieldStatus<TValue, any, any> | RegleFieldStatus<MaybeInput<TValue>, any, any> }>;
2539
+ }) | undefined>;
2534
2540
  //#endregion
2535
2541
  //#region src/core/refineRules.d.ts
2536
2542
  /**
@@ -2560,4 +2566,4 @@ declare function defineRules<TRules extends RegleUnknownRulesTree>(rules: TRules
2560
2566
  */
2561
2567
  declare function refineRules<TRules extends RegleUnknownRulesTree, TRefinement extends ReglePartialRuleTree<InferInput<TRules>> & RegleUnknownRulesTree>(rules: TRules, refinement: (state: Ref<InferInput<TRules>>) => TRefinement): (state: Ref<InferInput<TRules>>) => Merge<TRules, TRefinement>;
2562
2568
  //#endregion
2563
- export { type $InternalRegleStatus, type AllRulesDeclarations, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepReactiveState, type DefaultValidatorsTree, type FormRuleDeclaration, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InferSafeOutput, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleSingleField, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useScopedRegle, variantToRef };
2569
+ export { type $InternalRegleStatus, type AllRulesDeclarations, type ArrayElement, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepReactiveState, type DefaultValidatorsTree, type FormRuleDeclaration, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InferSafeOutput, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NoInferLegacy, type NonEmptyTuple, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleShortcutDefinition, type RegleSingleField, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useScopedRegle, variantToRef };