@regle/core 1.8.5 → 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.
@@ -25,7 +25,7 @@ type NoInferLegacy<A extends any> = [A][A extends any ? 0 : never];
25
25
  type ArrayElement<T> = T extends Array<infer U> ? U : never;
26
26
  type NonEmptyTuple<T> = [T, ...T[]] | T[];
27
27
  //#endregion
28
- //#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
29
29
  /**
30
30
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
31
31
 
@@ -33,27 +33,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
33
33
  */
34
34
  type Primitive = null | undefined | string | number | boolean | symbol | bigint;
35
35
  //#endregion
36
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts
37
- declare global {
38
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
39
- interface SymbolConstructor {
40
- readonly observable: symbol;
41
- }
42
- }
43
-
44
- /**
45
- @remarks
46
- The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
47
- As well, some guidance on making an `Observable` to not include `closed` property.
48
- @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
49
- @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
50
- @see https://github.com/benlesh/symbol-observable#making-an-object-observable
51
-
52
- @category Observable
53
- */
54
-
55
- //#endregion
56
- //#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
57
37
  /**
58
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).
59
39
 
@@ -115,7 +95,7 @@ Union extends unknown
115
95
  // The `& Union` is to allow indexing by the resulting type
116
96
  ? Intersection & Union : never;
117
97
  //#endregion
118
- //#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
119
99
  declare const emptyObjectSymbol: unique symbol;
120
100
 
121
101
  /**
@@ -147,7 +127,6 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
147
127
  type EmptyObject = {
148
128
  [emptyObjectSymbol]?: never;
149
129
  };
150
-
151
130
  /**
152
131
  Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
153
132
 
@@ -165,7 +144,81 @@ type Fail = IsEmptyObject<null>; //=> false
165
144
  */
166
145
  type IsEmptyObject<T> = T extends EmptyObject ? true : false;
167
146
  //#endregion
168
- //#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
169
222
  /**
170
223
  Extract all optional keys from the given type.
171
224
 
@@ -199,11 +252,11 @@ const update2: UpdateOperation<User> = {
199
252
 
200
253
  @category Utilities
201
254
  */
202
- type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
203
- ? (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`
204
- : 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;
205
258
  //#endregion
206
- //#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
207
260
  /**
208
261
  Extract all required keys from the given type.
209
262
 
@@ -228,11 +281,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
228
281
 
229
282
  @category Utilities
230
283
  */
231
- type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
232
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never; // Should never happen
233
-
284
+ type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
285
+ ? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
234
286
  //#endregion
235
- //#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
236
288
  /**
237
289
  Returns a boolean for whether the given type is `never`.
238
290
 
@@ -276,124 +328,174 @@ endIfEqual('abc', '123');
276
328
  */
277
329
  type IsNever$1<T> = [T] extends [never] ? true : false;
278
330
  //#endregion
279
- //#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
280
332
  /**
281
- 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'>`.
282
337
 
283
- @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'`.
284
341
 
285
342
  @example
286
343
  ```
287
- import type {IfNever} from 'type-fest';
344
+ import {If} from 'type-fest';
288
345
 
289
- type ShouldBeTrue = IfNever<never>;
290
- //=> true
346
+ type A = If<true, 'yes', 'no'>;
347
+ //=> 'yes'
291
348
 
292
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
293
- //=> 'bar'
294
- ```
349
+ type B = If<false, 'yes', 'no'>;
350
+ //=> 'no'
295
351
 
296
- @category Type Guard
297
- @category Utilities
298
- */
299
- type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever);
300
- //#endregion
301
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-any.d.ts
302
- // Can eventually be replaced with the built-in once this library supports
303
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
304
- type NoInfer<T> = T extends infer U ? U : never;
352
+ type C = If<boolean, 'yes', 'no'>;
353
+ //=> 'yes' | 'no'
305
354
 
306
- /**
307
- Returns a boolean for whether the given type is `any`.
308
-
309
- @link https://stackoverflow.com/a/49928360/1490091
355
+ type D = If<any, 'yes', 'no'>;
356
+ //=> 'yes' | 'no'
310
357
 
311
- 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
+ ```
312
361
 
313
362
  @example
314
363
  ```
315
- import type {IsAny} from 'type-fest';
364
+ import {If, IsAny, IsNever} from 'type-fest';
316
365
 
317
- const typedObject = {a: 1, b: 2} as const;
318
- const anyObject: any = {a: 1, b: 2};
366
+ type A = If<IsAny<unknown>, 'is any', 'not any'>;
367
+ //=> 'not any'
319
368
 
320
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
321
- return obj[key];
322
- }
369
+ type B = If<IsNever<never>, 'is never', 'not never'>;
370
+ //=> 'is never'
371
+ ```
323
372
 
324
- const typedA = get(typedObject, 'a');
325
- //=> 1
373
+ @example
374
+ ```
375
+ import {If, IsEqual} from 'type-fest';
326
376
 
327
- const anyA = get(anyObject, 'a');
328
- //=> 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'
329
384
  ```
330
385
 
331
386
  @category Type Guard
332
387
  @category Utilities
333
388
  */
334
- 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;
335
390
  //#endregion
336
- //#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
392
+ /**
393
+ Matches any primitive, `void`, `Date`, or `RegExp` value.
394
+ */
395
+ type BuiltIns = Primitive | void | Date | RegExp;
337
396
  /**
338
- Returns a boolean for whether the two given types are equal.
397
+ Test if the given function has multiple call signatures.
339
398
 
340
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
341
- @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.
342
400
 
343
- Use-cases:
344
- - 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`.
410
+
411
+ @example
412
+ ```
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'
416
+
417
+ // When `T` is `any` => Returns `IfAny` branch
418
+ type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
419
+ //=> 'IS_ANY'
420
+
421
+ // When `T` is `never` => Returns `IfNever` branch
422
+ type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
423
+ //=> 'IS_NEVER'
424
+ ```
425
+ */
426
+ type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever$1<T>, IfNever, IfNotAnyOrNever>>;
427
+ //#endregion
428
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-null.d.ts
429
+ /**
430
+ Returns a boolean for whether the given type is `null`.
345
431
 
346
432
  @example
347
433
  ```
348
- import type {IsEqual} from 'type-fest';
434
+ import type {IsNull} from 'type-fest';
435
+
436
+ type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
437
+
438
+ type Example1 = NonNullFallback<null, string>;
439
+ //=> string
349
440
 
350
- // This type returns a boolean for whether the given array includes the given item.
351
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
352
- type Includes<Value extends readonly any[], Item> =
353
- Value extends readonly [Value[0], ...infer rest]
354
- ? IsEqual<Value[0], Item> extends true
355
- ? true
356
- : Includes<rest, Item>
357
- : false;
441
+ type Example2 = NonNullFallback<number, string>;
442
+ //=? number
358
443
  ```
359
444
 
360
445
  @category Type Guard
361
446
  @category Utilities
362
447
  */
363
- type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
448
+ type IsNull<T> = [T] extends [null] ? true : false;
364
449
  //#endregion
365
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/or.d.ts
450
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/is-unknown.d.ts
366
451
  /**
367
- Returns a boolean for whether either of two given types are true.
452
+ Returns a boolean for whether the given type is `unknown`.
368
453
 
369
- Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
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.
370
457
 
371
458
  @example
372
459
  ```
373
- import type {Or} from 'type-fest';
460
+ import type {IsUnknown} from 'type-fest';
374
461
 
375
- Or<true, false>;
376
- //=> true
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;
377
467
 
378
- Or<false, false>;
379
- //=> false
380
- ```
468
+ class Store<TState> {
469
+ constructor(private state: TState) {}
381
470
 
382
- @see {@link And}
383
- */
384
- 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;
385
- //#endregion
386
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/keys.d.ts
387
- /**
388
- Disallows any of the given keys.
389
- */
390
- type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
471
+ execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
472
+ this.state = action(this.state, payload);
473
+ return this.state;
474
+ }
391
475
 
392
- /**
393
- Utility type to retrieve only literal keys from type.
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
394
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);
395
497
  //#endregion
396
- //#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
397
499
  /**
398
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.
399
501
 
@@ -453,7 +555,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
453
555
  */
454
556
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
455
557
  //#endregion
456
- //#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
457
559
  /**
458
560
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
459
561
 
@@ -546,7 +648,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
546
648
  */
547
649
  type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
548
650
  //#endregion
549
- //#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
550
652
  /**
551
653
  Pick only index signatures from the given object type, leaving out all explicitly defined properties.
552
654
 
@@ -594,7 +696,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
594
696
  */
595
697
  type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
596
698
  //#endregion
597
- //#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
598
700
  // Merges two objects without worrying about index signatures.
599
701
  type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
600
702
 
@@ -634,101 +736,7 @@ export type FooBar = Merge<Foo, Bar>;
634
736
  */
635
737
  type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
636
738
  //#endregion
637
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/if-any.d.ts
638
- /**
639
- An if-else-like type that resolves depending on whether the given type is `any`.
640
-
641
- @see {@link IsAny}
642
-
643
- @example
644
- ```
645
- import type {IfAny} from 'type-fest';
646
-
647
- type ShouldBeTrue = IfAny<any>;
648
- //=> true
649
-
650
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
651
- //=> 'bar'
652
- ```
653
-
654
- @category Type Guard
655
- @category Utilities
656
- */
657
- type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
658
- //#endregion
659
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/internal/type.d.ts
660
- /**
661
- Matches any primitive, `void`, `Date`, or `RegExp` value.
662
- */
663
- type BuiltIns = Primitive | void | Date | RegExp;
664
-
665
- /**
666
- Matches non-recursive types.
667
- */
668
-
669
- /**
670
- Test if the given function has multiple call signatures.
671
-
672
- Needed to handle the case of a single call signature with properties.
673
-
674
- Multiple call signatures cannot currently be supported due to a TypeScript limitation.
675
- @see https://github.com/microsoft/TypeScript/issues/29732
676
- */
677
- type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
678
- (...arguments_: infer A): unknown;
679
- (...arguments_: infer B): unknown;
680
- } ? B extends A ? A extends B ? false : true : true : false;
681
-
682
- /**
683
- Returns a boolean for whether the given `boolean` is not `false`.
684
- */
685
-
686
- /**
687
- Returns a boolean for whether the given type is a union type.
688
-
689
- @example
690
- ```
691
- type A = IsUnion<string | number>;
692
- //=> true
693
-
694
- type B = IsUnion<string>;
695
- //=> false
696
- ```
697
- */
698
- type IsUnion$1<T> = InternalIsUnion<T>;
699
-
700
- /**
701
- The actual implementation of `IsUnion`.
702
- */
703
- type InternalIsUnion<T, U = T> = (
704
- // @link https://ghaiklor.github.io/type-challenges-solutions/en/medium-isunion.html
705
- IsNever$1<T> extends true ? false : T extends any ? [U] extends [T] ? false : true : never) extends infer Result
706
- // In some cases `Result` will return `false | true` which is `boolean`,
707
- // that means `T` has at least two types and it's a union type,
708
- // so we will return `true` instead of `boolean`.
709
- ? boolean extends Result ? true : Result : never; // Should never happen
710
-
711
- /**
712
- An if-else-like type that resolves depending on whether the given type is `any` or `never`.
713
-
714
- @example
715
- ```
716
- // When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
717
- type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
718
- //=> 'VALID'
719
-
720
- // When `T` is `any` => Returns `IfAny` branch
721
- type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
722
- //=> 'IS_ANY'
723
-
724
- // When `T` is `never` => Returns `IfNever` branch
725
- type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
726
- //=> 'IS_NEVER'
727
- ```
728
- */
729
- type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever$1<T> extends true ? IfNever : IfNotAnyOrNever;
730
- //#endregion
731
- //#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
732
740
  /**
733
741
  Merges user specified options with default options.
734
742
 
@@ -781,10 +789,95 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
781
789
  // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
782
790
  ```
783
791
  */
784
- 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>`
785
- >>;
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>>;
786
879
  //#endregion
787
- //#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
788
881
  /**
789
882
  Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
790
883
 
@@ -814,10 +907,10 @@ const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
814
907
 
815
908
  @category Object
816
909
  */
817
- 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>>>>;
818
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>;
819
912
  //#endregion
820
- //#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
821
914
  /**
822
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.
823
916
 
@@ -848,10 +941,35 @@ const responder3: Responder = {
848
941
 
849
942
  @category Object
850
943
  */
851
- 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>>>>;
852
945
  type _RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
853
946
  //#endregion
854
- //#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
855
973
  /**
856
974
  @see {@link PartialDeep}
857
975
  */
@@ -866,24 +984,23 @@ type PartialDeepOptions = {
866
984
  Allows `undefined` values in non-tuple arrays.
867
985
  - When set to `true`, elements of non-tuple arrays can be `undefined`.
868
986
  - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
869
- @default true
987
+ @default false
870
988
  @example
871
- 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:
872
990
  ```
873
991
  import type {PartialDeep} from 'type-fest';
874
992
  type Settings = {
875
993
  languages: string[];
876
994
  };
877
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
878
- partialSettings.languages = [undefined]; // Error
879
- partialSettings.languages = []; // Ok
995
+ declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
996
+ partialSettings.languages = [undefined]; // OK
880
997
  ```
881
998
  */
882
999
  readonly allowUndefinedInNonTupleArrays?: boolean;
883
1000
  };
884
1001
  type DefaultPartialDeepOptions = {
885
1002
  recurseIntoArrays: false;
886
- allowUndefinedInNonTupleArrays: true;
1003
+ allowUndefinedInNonTupleArrays: false;
887
1004
  };
888
1005
 
889
1006
  /**
@@ -897,19 +1014,19 @@ Use-cases:
897
1014
  ```
898
1015
  import type {PartialDeep} from 'type-fest';
899
1016
 
900
- const settings: Settings = {
1017
+ let settings = {
901
1018
  textEditor: {
902
1019
  fontSize: 14,
903
1020
  fontColor: '#000000',
904
- fontWeight: 400
1021
+ fontWeight: 400,
905
1022
  },
906
1023
  autocomplete: false,
907
- autosave: true
1024
+ autosave: true,
908
1025
  };
909
1026
 
910
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
911
- return {...settings, ...savedSettings};
912
- }
1027
+ const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
1028
+ {...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
1029
+ );
913
1030
 
914
1031
  settings = applySavedSettings({textEditor: {fontWeight: 500}});
915
1032
  ```
@@ -919,13 +1036,15 @@ By default, this does not affect elements in array and tuple types. You can chan
919
1036
  ```
920
1037
  import type {PartialDeep} from 'type-fest';
921
1038
 
922
- type Settings = {
923
- languages: string[];
924
- }
1039
+ type Shape = {
1040
+ dimensions: [number, number];
1041
+ };
925
1042
 
926
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
927
- languages: [undefined]
1043
+ const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
1044
+ dimensions: [], // OK
928
1045
  };
1046
+
1047
+ partialShape.dimensions = [15]; // OK
929
1048
  ```
930
1049
 
931
1050
  @see {@link PartialDeepOptions}
@@ -969,9 +1088,7 @@ Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for
969
1088
  */
970
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> });
971
1090
  //#endregion
972
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/required-deep.d.ts
973
- type ExcludeUndefined<T> = Exclude<T, undefined>;
974
-
1091
+ //#region ../../node_modules/.pnpm/type-fest@5.0.0/node_modules/type-fest/source/required-deep.d.ts
975
1092
  /**
976
1093
  Create a type from another type with all keys and nested keys set to required.
977
1094
 
@@ -985,23 +1102,23 @@ import type {RequiredDeep} from 'type-fest';
985
1102
 
986
1103
  type Settings = {
987
1104
  textEditor?: {
988
- fontSize?: number | undefined;
989
- fontColor?: string | undefined;
1105
+ fontSize?: number;
1106
+ fontColor?: string;
990
1107
  fontWeight?: number | undefined;
991
- }
992
- autocomplete?: boolean | undefined;
1108
+ };
1109
+ autocomplete?: boolean;
993
1110
  autosave?: boolean | undefined;
994
1111
  };
995
1112
 
996
1113
  type RequiredSettings = RequiredDeep<Settings>;
997
- // type RequiredSettings = {
1114
+ //=> {
998
1115
  // textEditor: {
999
1116
  // fontSize: number;
1000
1117
  // fontColor: string;
1001
- // fontWeight: number;
1002
- // }
1118
+ // fontWeight: number | undefined;
1119
+ // };
1003
1120
  // autocomplete: boolean;
1004
- // autosave: boolean;
1121
+ // autosave: boolean | undefined;
1005
1122
  // }
1006
1123
  ```
1007
1124
 
@@ -1013,14 +1130,10 @@ Note that types containing overloaded functions are not made deeply required due
1013
1130
  @category Set
1014
1131
  @category Map
1015
1132
  */
1016
- 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
1017
- ? ItemType[] extends E // Test for arrays (non-tuples) specifically
1018
- ? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
1019
- : RequiredObjectDeep<E> // Tuples behave properly
1020
- : 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;
1021
1134
  type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
1022
1135
  //#endregion
1023
- //#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
1024
1137
  /**
1025
1138
  Returns the last element of a union type.
1026
1139
 
@@ -1069,76 +1182,6 @@ const petList = Object.keys(pets) as UnionToTuple<Pet>;
1069
1182
  */
1070
1183
  type UnionToTuple<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
1071
1184
  //#endregion
1072
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-null.d.ts
1073
- /**
1074
- Returns a boolean for whether the given type is `null`.
1075
-
1076
- @example
1077
- ```
1078
- import type {IsNull} from 'type-fest';
1079
-
1080
- type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
1081
-
1082
- type Example1 = NonNullFallback<null, string>;
1083
- //=> string
1084
-
1085
- type Example2 = NonNullFallback<number, string>;
1086
- //=? number
1087
- ```
1088
-
1089
- @category Type Guard
1090
- @category Utilities
1091
- */
1092
- type IsNull<T> = [T] extends [null] ? true : false;
1093
- //#endregion
1094
- //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/is-unknown.d.ts
1095
- /**
1096
- Returns a boolean for whether the given type is `unknown`.
1097
-
1098
- @link https://github.com/dsherret/conditional-type-checks/pull/16
1099
-
1100
- Useful in type utilities, such as when dealing with unknown data from API calls.
1101
-
1102
- @example
1103
- ```
1104
- import type {IsUnknown} from 'type-fest';
1105
-
1106
- // https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
1107
- type Action<TState, TPayload = void> =
1108
- IsUnknown<TPayload> extends true
1109
- ? (state: TState) => TState,
1110
- : (state: TState, payload: TPayload) => TState;
1111
-
1112
- class Store<TState> {
1113
- constructor(private state: TState) {}
1114
-
1115
- execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
1116
- this.state = action(this.state, payload);
1117
- return this.state;
1118
- }
1119
-
1120
- // ... other methods
1121
- }
1122
-
1123
- const store = new Store({value: 1});
1124
- declare const someExternalData: unknown;
1125
-
1126
- store.execute(state => ({value: state.value + 1}));
1127
- //=> `TPayload` is `void`
1128
-
1129
- store.execute((state, payload) => ({value: state.value + payload}), 5);
1130
- //=> `TPayload` is `5`
1131
-
1132
- store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
1133
- //=> Errors: `action` is `(state: TState) => TState`
1134
- ```
1135
-
1136
- @category Utilities
1137
- */
1138
- type IsUnknown<T> = (unknown extends T // `T` can be `unknown` or `any`
1139
- ? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
1140
- ? true : false : false);
1141
- //#endregion
1142
1185
  //#region src/types/core/modifiers.types.d.ts
1143
1186
  interface RegleBehaviourOptions {
1144
1187
  /**
@@ -1333,30 +1376,16 @@ type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | u
1333
1376
  * Negates a boolean type.
1334
1377
  */
1335
1378
  type Not<T extends boolean> = T extends true ? false : true;
1336
- /**
1337
- * Returns `true` if at least one of the types in the
1338
- * {@linkcode Types} array is `true`, otherwise returns `false`.
1339
- */
1340
-
1341
1379
  /**
1342
1380
  * Checks if the given type is `never`.
1343
1381
  */
1344
1382
  type IsNever<T> = [T] extends [never] ? true : false;
1345
- /**
1346
- * Checks if the given type is `any`.
1347
- */
1348
-
1349
1383
  /**
1350
1384
  * Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
1351
1385
  * 1. If either type is `never`, the result is `true` iff the other type is also `never`.
1352
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`.
1353
1387
  */
1354
1388
  type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
1355
- /**
1356
- * Checks if the {@linkcode Left} type extends the {@linkcode Right} type,
1357
- * excluding `any` or `never`.
1358
- */
1359
-
1360
1389
  /**
1361
1390
  * Convert a union to an intersection.
1362
1391
  * `A | B | C` -\> `A & B & C`
@@ -1379,17 +1408,6 @@ type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends t
1379
1408
  */
1380
1409
  type UnionToTuple$1<Union> = TuplifyUnion<Union>;
1381
1410
  type IsUnion<T> = Not<Extends<UnionToTuple$1<T>['length'], 1>>;
1382
- /**
1383
- * A recursive version of `Pick` that selects properties from the left type that are present in the right type.
1384
- * The "leaf" types from `Left` are used - only the keys of `Right` are considered.
1385
- *
1386
- * @example
1387
- * ```ts
1388
- * const user = {email: 'a@b.com', name: 'John Doe', address: {street: '123 2nd St', city: 'New York', zip: '10001', state: 'NY', country: 'USA'}}
1389
- *
1390
- * type Result = DeepPickMatchingProps<typeof user, {name: unknown; address: {city: unknown}}> // {name: string, address: {city: string}}
1391
- * ```
1392
- */
1393
1411
  //#endregion
1394
1412
  //#region src/types/core/variants.types.d.ts
1395
1413
  type NarrowVariant<TRoot extends {
@@ -1632,7 +1650,7 @@ type IsLiteral<T> = string extends T ? false : true;
1632
1650
  /**
1633
1651
  * Returned typed of rules created with `createRule`
1634
1652
  * */
1635
- 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> {
1636
1654
  validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
1637
1655
  message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
1638
1656
  active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
@@ -1641,10 +1659,6 @@ interface RegleRuleDefinition<TValue extends unknown = unknown, TParams extends
1641
1659
  _value?: IsLiteral<TValue> extends true ? TValue : any;
1642
1660
  exec: (value: Maybe<TFilteredValue>) => TAsync extends false ? TMetaData : Promise<TMetaData>;
1643
1661
  }
1644
- /**
1645
- * @internal
1646
- * */
1647
-
1648
1662
  /**
1649
1663
  * Rules with params created with `createRules` are callable while being customizable
1650
1664
  */
@@ -1688,10 +1702,6 @@ type PossibleRegleRuleMetadataConsumer<TValue> = {
1688
1702
  } & DefaultMetadataProperties & {
1689
1703
  $params?: [...any[]];
1690
1704
  };
1691
- /**
1692
- * @internal
1693
- */
1694
-
1695
1705
  /**
1696
1706
  * Generic types for a created RegleRule
1697
1707
  */
@@ -1741,11 +1751,6 @@ interface RegleRuleCore<TValue extends any, TParams extends any[] = [], TAsync e
1741
1751
  type?: string;
1742
1752
  async?: boolean;
1743
1753
  }
1744
- /**
1745
- * @internal
1746
- * createRule arguments options
1747
- */
1748
-
1749
1754
  type RegleRuleTypeReturn<TValue, TParams extends [...any[]]> = {
1750
1755
  value: TValue;
1751
1756
  params: [...TParams];
@@ -1895,10 +1900,6 @@ type $InternalRegleCollectionRuleDecl = $InternalRegleRuleDecl & {
1895
1900
  * @public
1896
1901
  */
1897
1902
  type InlineRuleDeclaration<TValue extends any = any, TParams extends any[] = any[], TReturn extends RegleRuleMetadataDefinition | Promise<RegleRuleMetadataDefinition> = boolean> = (value: Maybe<TValue>, ...args: UnwrapRegleUniversalParams<TParams>) => TReturn;
1898
- /**
1899
- * @internal
1900
- */
1901
-
1902
1903
  /**
1903
1904
  * @public
1904
1905
  * Regroup inline and registered rules
@@ -2337,11 +2338,6 @@ declare function createRule<TValue extends any, TParams extends any[], TReturn e
2337
2338
  * Removing Ref and executing function to return the unwrapped value
2338
2339
  */
2339
2340
  declare function unwrapRuleParameters<TParams extends any[]>(params: MaybeRefOrGetter[]): TParams;
2340
- /**
2341
- * Returns a clean list of parameters
2342
- * Removing Ref and executing function to return the unwrapped value
2343
- */
2344
-
2345
2341
  //#endregion
2346
2342
  //#region src/core/defineRegleConfig.d.ts
2347
2343
  /**
@@ -2519,9 +2515,14 @@ declare function createVariant<TForm extends Record<string, any>, TDiscriminant
2519
2515
  */
2520
2516
  declare function narrowVariant<TRoot extends {
2521
2517
  [x: string]: unknown;
2518
+ $fields: {
2519
+ [x: string]: unknown;
2520
+ };
2522
2521
  }, const TKey extends keyof TRoot, const TValue extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any>>> extends {
2523
2522
  $value: infer V;
2524
- } ? 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
+ };
2525
2526
  /**
2526
2527
  * Narrow a nested variant root to a reactive reference
2527
2528
  *
@@ -2533,7 +2534,9 @@ declare function narrowVariant<TRoot extends {
2533
2534
  */
2534
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 {
2535
2536
  $value: infer V;
2536
- } ? 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>;
2537
2540
  //#endregion
2538
2541
  //#region src/core/refineRules.d.ts
2539
2542
  /**
@@ -2563,4 +2566,4 @@ declare function defineRules<TRules extends RegleUnknownRulesTree>(rules: TRules
2563
2566
  */
2564
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>;
2565
2568
  //#endregion
2566
- 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 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 };
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 };