@react-querybuilder/datetime 8.9.1 → 8.10.0

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.
Files changed (62) hide show
  1. package/dist/cjs/getDatetimeRuleProcessorSQL-COEhnVIZ.js +478 -0
  2. package/dist/cjs/{getDatetimeRuleProcessorSQL-D95jgDK6.js.map → getDatetimeRuleProcessorSQL-COEhnVIZ.js.map} +1 -1
  3. package/dist/cjs/react-querybuilder_datetime.cjs.development.d.ts +1 -1
  4. package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.d.ts +1 -1
  5. package/dist/cjs/react-querybuilder_datetime.cjs.development.date-fns.js +1 -1
  6. package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.d.ts +1 -1
  7. package/dist/cjs/react-querybuilder_datetime.cjs.development.dayjs.js +1 -1
  8. package/dist/cjs/react-querybuilder_datetime.cjs.development.js +1 -1
  9. package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.d.ts +1 -1
  10. package/dist/cjs/react-querybuilder_datetime.cjs.development.jsdate.js +1 -1
  11. package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.d.ts +1 -1
  12. package/dist/cjs/react-querybuilder_datetime.cjs.development.luxon.js +1 -1
  13. package/dist/cjs/react-querybuilder_datetime.cjs.production.d.ts +1 -1
  14. package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.d.ts +1 -1
  15. package/dist/cjs/react-querybuilder_datetime.cjs.production.date-fns.js +1 -1
  16. package/dist/cjs/react-querybuilder_datetime.cjs.production.dayjs.d.ts +1 -1
  17. package/dist/cjs/react-querybuilder_datetime.cjs.production.dayjs.js +1 -1
  18. package/dist/cjs/react-querybuilder_datetime.cjs.production.js +1 -1
  19. package/dist/cjs/react-querybuilder_datetime.cjs.production.js.map +1 -1
  20. package/dist/cjs/react-querybuilder_datetime.cjs.production.jsdate.d.ts +1 -1
  21. package/dist/cjs/react-querybuilder_datetime.cjs.production.jsdate.js +1 -1
  22. package/dist/cjs/react-querybuilder_datetime.cjs.production.luxon.d.ts +1 -1
  23. package/dist/cjs/react-querybuilder_datetime.cjs.production.luxon.js +1 -1
  24. package/dist/{types-CDEkL2M_.d.mts → cjs/types-C3iwOCvi.d.ts} +375 -310
  25. package/dist/{getDatetimeRuleProcessorSQL-KYRPP9qd.mjs → getDatetimeRuleProcessorSQL-CW5JXMXx.mjs} +12 -14
  26. package/dist/{getDatetimeRuleProcessorSQL-KYRPP9qd.mjs.map → getDatetimeRuleProcessorSQL-CW5JXMXx.mjs.map} +1 -1
  27. package/dist/{getDatetimeRuleProcessorSQL-CN80oEFK.js → getDatetimeRuleProcessorSQL-DS_x8OLw.js} +11 -13
  28. package/dist/{getDatetimeRuleProcessorSQL-CN80oEFK.js.map → getDatetimeRuleProcessorSQL-DS_x8OLw.js.map} +1 -1
  29. package/dist/react-querybuilder_datetime.d.mts +1 -1
  30. package/dist/react-querybuilder_datetime.date-fns.d.mts +1 -1
  31. package/dist/react-querybuilder_datetime.date-fns.mjs +1 -1
  32. package/dist/react-querybuilder_datetime.dayjs.d.mts +1 -1
  33. package/dist/react-querybuilder_datetime.dayjs.mjs +1 -1
  34. package/dist/react-querybuilder_datetime.jsdate.d.mts +1 -1
  35. package/dist/react-querybuilder_datetime.jsdate.mjs +1 -1
  36. package/dist/react-querybuilder_datetime.legacy-esm.d.ts +1 -1
  37. package/dist/react-querybuilder_datetime.legacy-esm.date-fns.d.ts +1 -1
  38. package/dist/react-querybuilder_datetime.legacy-esm.date-fns.js +1 -1
  39. package/dist/react-querybuilder_datetime.legacy-esm.dayjs.d.ts +1 -1
  40. package/dist/react-querybuilder_datetime.legacy-esm.dayjs.js +1 -1
  41. package/dist/react-querybuilder_datetime.legacy-esm.js +1 -1
  42. package/dist/react-querybuilder_datetime.legacy-esm.jsdate.d.ts +1 -1
  43. package/dist/react-querybuilder_datetime.legacy-esm.jsdate.js +1 -1
  44. package/dist/react-querybuilder_datetime.legacy-esm.luxon.d.ts +1 -1
  45. package/dist/react-querybuilder_datetime.legacy-esm.luxon.js +1 -1
  46. package/dist/react-querybuilder_datetime.luxon.d.mts +1 -1
  47. package/dist/react-querybuilder_datetime.luxon.mjs +1 -1
  48. package/dist/react-querybuilder_datetime.mjs +1 -1
  49. package/dist/react-querybuilder_datetime.production.d.mts +1 -1
  50. package/dist/react-querybuilder_datetime.production.date-fns.d.mts +1 -1
  51. package/dist/react-querybuilder_datetime.production.date-fns.mjs +1 -1
  52. package/dist/react-querybuilder_datetime.production.dayjs.d.mts +1 -1
  53. package/dist/react-querybuilder_datetime.production.dayjs.mjs +1 -1
  54. package/dist/react-querybuilder_datetime.production.jsdate.d.mts +1 -1
  55. package/dist/react-querybuilder_datetime.production.jsdate.mjs +1 -1
  56. package/dist/react-querybuilder_datetime.production.luxon.d.mts +1 -1
  57. package/dist/react-querybuilder_datetime.production.luxon.mjs +1 -1
  58. package/dist/react-querybuilder_datetime.production.mjs +1 -1
  59. package/dist/{cjs/types-QCQUGVZa.d.ts → types-BQXdgbuB.d.mts} +375 -310
  60. package/dist/{types-EgfSemtR.d.ts → types-Dm-PhQtt.d.ts} +375 -310
  61. package/package.json +14 -14
  62. package/dist/cjs/getDatetimeRuleProcessorSQL-D95jgDK6.js +0 -2
@@ -1,35 +1,196 @@
1
1
  import { RulesLogic } from "json-logic-js";
2
2
 
3
- //#region ../core/src/types/type-fest/is-equal.d.ts
3
+ //#region ../../node_modules/type-fest/source/observable-like.d.ts
4
+ declare global {
5
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
6
+ interface SymbolConstructor {
7
+ readonly observable: symbol;
8
+ }
9
+ }
4
10
 
5
11
  /**
6
- Returns a boolean for whether the two given types are equal.
12
+ @remarks
13
+ The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
14
+ As well, some guidance on making an `Observable` to not include `closed` property.
15
+ @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
16
+ @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
17
+ @see https://github.com/benlesh/symbol-observable#making-an-object-observable
7
18
 
8
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
9
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
19
+ @category Observable
20
+ */
10
21
 
11
- Use-cases:
12
- - If you want to make a conditional branch based on the result of a comparison of two types.
22
+ //#endregion
23
+ //#region ../../node_modules/type-fest/source/union-to-intersection.d.ts
24
+ /**
25
+ 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).
26
+
27
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
13
28
 
14
29
  @example
15
30
  ```
16
- import type {IsEqual} from 'type-fest';
31
+ import type {UnionToIntersection} from 'type-fest';
17
32
 
18
- // This type returns a boolean for whether the given array includes the given item.
19
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
20
- type Includes<Value extends readonly any[], Item> =
21
- Value extends readonly [Value[0], ...infer rest]
22
- ? IsEqual<Value[0], Item> extends true
23
- ? true
24
- : Includes<rest, Item>
25
- : false;
33
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
34
+
35
+ type Intersection = UnionToIntersection<Union>;
36
+ //=> {the(): void; great(arg: string): void; escape: boolean};
26
37
  ```
27
38
 
28
- @group type-fest
39
+ A more applicable example which could make its way into your library code follows.
40
+
41
+ @example
42
+ ```
43
+ import type {UnionToIntersection} from 'type-fest';
44
+
45
+ class CommandOne {
46
+ commands: {
47
+ a1: () => undefined,
48
+ b1: () => undefined,
49
+ }
50
+ }
51
+
52
+ class CommandTwo {
53
+ commands: {
54
+ a2: (argA: string) => undefined,
55
+ b2: (argB: string) => undefined,
56
+ }
57
+ }
58
+
59
+ const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
60
+ type Union = typeof union;
61
+ //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
62
+
63
+ type Intersection = UnionToIntersection<Union>;
64
+ //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
65
+ ```
66
+
67
+ @category Type
68
+ */
69
+ type UnionToIntersection<Union> = (
70
+ // `extends unknown` is always going to be the case and is used to convert the
71
+ // `Union` into a [distributive conditional
72
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
73
+ Union extends unknown
74
+ // The union type is used as the only argument to a function since the union
75
+ // of function arguments is an intersection.
76
+ ? (distributedUnion: Union) => void
77
+ // This won't happen.
78
+ : never
79
+ // Infer the `Intersection` type since TypeScript represents the positional
80
+ // arguments of unions of functions as an intersection of the union.
81
+ ) extends ((mergedIntersection: infer Intersection) => void)
82
+ // The `& Union` is to allow indexing by the resulting type
83
+ ? Intersection & Union : never;
84
+ //#endregion
85
+ //#region ../../node_modules/type-fest/source/keys-of-union.d.ts
86
+ /**
87
+ Create a union of all keys from a given type, even those exclusive to specific union members.
88
+
89
+ Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
90
+
91
+ @link https://stackoverflow.com/a/49402091
92
+
93
+ @example
94
+ ```
95
+ import type {KeysOfUnion} from 'type-fest';
96
+
97
+ type A = {
98
+ common: string;
99
+ a: number;
100
+ };
101
+
102
+ type B = {
103
+ common: string;
104
+ b: string;
105
+ };
106
+
107
+ type C = {
108
+ common: string;
109
+ c: boolean;
110
+ };
111
+
112
+ type Union = A | B | C;
113
+
114
+ type CommonKeys = keyof Union;
115
+ //=> 'common'
116
+
117
+ type AllKeys = KeysOfUnion<Union>;
118
+ //=> 'common' | 'a' | 'b' | 'c'
119
+ ```
120
+
121
+ @category Object
29
122
  */
30
- type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
123
+ type KeysOfUnion<ObjectType> =
124
+ // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
125
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
126
+ //#endregion
127
+ //#region ../../node_modules/type-fest/source/optional-keys-of.d.ts
128
+ /**
129
+ Extract all optional keys from the given type.
130
+
131
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
132
+
133
+ @example
134
+ ```
135
+ import type {OptionalKeysOf, Except} from 'type-fest';
136
+
137
+ interface User {
138
+ name: string;
139
+ surname: string;
140
+
141
+ luckyNumber?: number;
142
+ }
143
+
144
+ const REMOVE_FIELD = Symbol('remove field symbol');
145
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
146
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
147
+ };
148
+
149
+ const update1: UpdateOperation<User> = {
150
+ name: 'Alice'
151
+ };
152
+
153
+ const update2: UpdateOperation<User> = {
154
+ name: 'Bob',
155
+ luckyNumber: REMOVE_FIELD
156
+ };
157
+ ```
158
+
159
+ @category Utilities
160
+ */
161
+ type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
162
+ ? (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`
163
+ : never;
164
+ //#endregion
165
+ //#region ../../node_modules/type-fest/source/required-keys-of.d.ts
166
+ /**
167
+ Extract all required keys from the given type.
168
+
169
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
170
+
171
+ @example
172
+ ```
173
+ import type {RequiredKeysOf} from 'type-fest';
174
+
175
+ declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
176
+
177
+ interface User {
178
+ name: string;
179
+ surname: string;
180
+
181
+ luckyNumber?: number;
182
+ }
183
+
184
+ const validator1 = createValidation<User>('name', value => value.length < 25);
185
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
186
+ ```
187
+
188
+ @category Utilities
189
+ */
190
+ type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
191
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
31
192
  //#endregion
32
- //#region ../core/src/types/type-fest/is-never.d.ts
193
+ //#region ../../node_modules/type-fest/source/is-never.d.ts
33
194
  /**
34
195
  Returns a boolean for whether the given type is `never`.
35
196
 
@@ -45,20 +206,20 @@ import type {IsNever, And} from 'type-fest';
45
206
 
46
207
  // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
47
208
  type AreStringsEqual<A extends string, B extends string> =
48
- And<
49
- IsNever<Exclude<A, B>> extends true ? true : false,
50
- IsNever<Exclude<B, A>> extends true ? true : false
51
- >;
209
+ And<
210
+ IsNever<Exclude<A, B>> extends true ? true : false,
211
+ IsNever<Exclude<B, A>> extends true ? true : false
212
+ >;
52
213
 
53
214
  type EndIfEqual<I extends string, O extends string> =
54
- AreStringsEqual<I, O> extends true
55
- ? never
56
- : void;
215
+ AreStringsEqual<I, O> extends true
216
+ ? never
217
+ : void;
57
218
 
58
219
  function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
59
- if (input === output) {
60
- process.exit(0);
61
- }
220
+ if (input === output) {
221
+ process.exit(0);
222
+ }
62
223
  }
63
224
 
64
225
  endIfEqual('abc', 'abc');
@@ -68,11 +229,12 @@ endIfEqual('abc', '123');
68
229
  //=> void
69
230
  ```
70
231
 
71
- @group type-fest
232
+ @category Type Guard
233
+ @category Utilities
72
234
  */
73
235
  type IsNever<T> = [T] extends [never] ? true : false;
74
236
  //#endregion
75
- //#region ../core/src/types/type-fest/if-never.d.ts
237
+ //#region ../../node_modules/type-fest/source/if-never.d.ts
76
238
  /**
77
239
  An if-else-like type that resolves depending on whether the given type is `never`.
78
240
 
@@ -89,11 +251,12 @@ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
89
251
  //=> 'bar'
90
252
  ```
91
253
 
92
- @group type-fest
254
+ @category Type Guard
255
+ @category Utilities
93
256
  */
94
257
  type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
95
258
  //#endregion
96
- //#region ../core/src/types/type-fest/unknown-array.d.ts
259
+ //#region ../../node_modules/type-fest/source/unknown-array.d.ts
97
260
  /**
98
261
  Represents an array with `unknown` value.
99
262
 
@@ -115,16 +278,15 @@ type C = IsArray<string>;
115
278
  //=> false
116
279
  ```
117
280
 
118
- @group type-fest
281
+ @category Type
282
+ @category Array
119
283
  */
120
284
  type UnknownArray = readonly unknown[];
121
285
  //#endregion
122
- //#region ../core/src/types/type-fest/internal/array.d.ts
286
+ //#region ../../node_modules/type-fest/source/internal/array.d.ts
123
287
 
124
288
  /**
125
289
  Returns whether the given array `T` is readonly.
126
-
127
- @group type-fest
128
290
  */
129
291
  type IsArrayReadonly<T extends UnknownArray> = IfNever$1<T, false, T extends unknown[] ? false : true>;
130
292
  /**
@@ -137,9 +299,9 @@ An if-else-like type that resolves depending on whether the given array is reado
137
299
  import type {ArrayTail} from 'type-fest';
138
300
 
139
301
  type ReadonlyPreservingArrayTail<TArray extends readonly unknown[]> =
140
- ArrayTail<TArray> extends infer Tail
141
- ? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
142
- : never;
302
+ ArrayTail<TArray> extends infer Tail
303
+ ? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
304
+ : never;
143
305
 
144
306
  type ReadonlyTail = ReadonlyPreservingArrayTail<readonly [string, number, boolean]>;
145
307
  //=> readonly [number, boolean]
@@ -153,13 +315,14 @@ type ShouldBeTrue = IfArrayReadonly<readonly unknown[]>;
153
315
  type ShouldBeBar = IfArrayReadonly<unknown[], 'foo', 'bar'>;
154
316
  //=> 'bar'
155
317
  ```
156
-
157
- @group type-fest
158
318
  */
159
319
  type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> = IsArrayReadonly<T> extends infer Result ? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly : never;
160
320
  //#endregion
161
- //#region ../core/src/types/type-fest/is-any.d.ts
321
+ //#region ../../node_modules/type-fest/source/is-any.d.ts
322
+ // Can eventually be replaced with the built-in once this library supports
323
+ // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
162
324
  type NoInfer<T> = T extends infer U ? U : never;
325
+
163
326
  /**
164
327
  Returns a boolean for whether the given type is `any`.
165
328
 
@@ -175,7 +338,7 @@ const typedObject = {a: 1, b: 2} as const;
175
338
  const anyObject: any = {a: 1, b: 2};
176
339
 
177
340
  function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
178
- return obj[key];
341
+ return obj[key];
179
342
  }
180
343
 
181
344
  const typedA = get(typedObject, 'a');
@@ -185,11 +348,41 @@ const anyA = get(anyObject, 'a');
185
348
  //=> any
186
349
  ```
187
350
 
188
- @group type-fest
351
+ @category Type Guard
352
+ @category Utilities
189
353
  */
190
354
  type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
191
355
  //#endregion
192
- //#region ../core/src/types/type-fest/simplify.d.ts
356
+ //#region ../../node_modules/type-fest/source/is-equal.d.ts
357
+ /**
358
+ Returns a boolean for whether the two given types are equal.
359
+
360
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
361
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
362
+
363
+ Use-cases:
364
+ - If you want to make a conditional branch based on the result of a comparison of two types.
365
+
366
+ @example
367
+ ```
368
+ import type {IsEqual} from 'type-fest';
369
+
370
+ // This type returns a boolean for whether the given array includes the given item.
371
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
372
+ type Includes<Value extends readonly any[], Item> =
373
+ Value extends readonly [Value[0], ...infer rest]
374
+ ? IsEqual<Value[0], Item> extends true
375
+ ? true
376
+ : Includes<rest, Item>
377
+ : false;
378
+ ```
379
+
380
+ @category Type Guard
381
+ @category Utilities
382
+ */
383
+ type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
384
+ //#endregion
385
+ //#region ../../node_modules/type-fest/source/simplify.d.ts
193
386
  /**
194
387
  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.
195
388
 
@@ -198,13 +391,13 @@ Useful to flatten the type output to improve type hints shown in editors. And al
198
391
  import type {Simplify} from 'type-fest';
199
392
 
200
393
  type PositionProps = {
201
- top: number;
202
- left: number;
394
+ top: number;
395
+ left: number;
203
396
  };
204
397
 
205
398
  type SizeProps = {
206
- width: number;
207
- height: number;
399
+ width: number;
400
+ height: number;
208
401
  };
209
402
 
210
403
  // In your editor, hovering over `Props` will show a flattened object with all the properties.
@@ -220,15 +413,15 @@ If the type definition must be an interface (perhaps it was defined in a third-p
220
413
  import type {Simplify} from 'type-fest';
221
414
 
222
415
  interface SomeInterface {
223
- foo: number;
224
- bar?: string;
225
- baz: number | undefined;
416
+ foo: number;
417
+ bar?: string;
418
+ baz: number | undefined;
226
419
  }
227
420
 
228
421
  type SomeType = {
229
- foo: number;
230
- bar?: string;
231
- baz: number | undefined;
422
+ foo: number;
423
+ bar?: string;
424
+ baz: number | undefined;
232
425
  };
233
426
 
234
427
  const literal = {foo: 123, bar: 'hello', baz: 456};
@@ -245,163 +438,11 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
245
438
 
246
439
  @link https://github.com/microsoft/TypeScript/issues/15300
247
440
  @see SimplifyDeep
248
-
249
- @group type-fest
441
+ @category Object
250
442
  */
251
443
  type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
252
444
  //#endregion
253
- //#region ../core/src/types/type-fest/union-to-intersection.d.ts
254
- /**
255
- 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).
256
-
257
- Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
258
-
259
- @example
260
- ```
261
- import type {UnionToIntersection} from 'type-fest';
262
-
263
- type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
264
-
265
- type Intersection = UnionToIntersection<Union>;
266
- //=> {the(): void; great(arg: string): void; escape: boolean};
267
- ```
268
-
269
- A more applicable example which could make its way into your library code follows.
270
-
271
- @example
272
- ```
273
- import type {UnionToIntersection} from 'type-fest';
274
-
275
- class CommandOne {
276
- commands: {
277
- a1: () => undefined,
278
- b1: () => undefined,
279
- }
280
- }
281
-
282
- class CommandTwo {
283
- commands: {
284
- a2: (argA: string) => undefined,
285
- b2: (argB: string) => undefined,
286
- }
287
- }
288
-
289
- const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
290
- type Union = typeof union;
291
- //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
292
-
293
- type Intersection = UnionToIntersection<Union>;
294
- //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
295
- ```
296
-
297
- @group type-fest
298
- */
299
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
300
- //#endregion
301
- //#region ../core/src/types/type-fest/keys-of-union.d.ts
302
- /**
303
- Create a union of all keys from a given type, even those exclusive to specific union members.
304
-
305
- Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
306
-
307
- @link https://stackoverflow.com/a/49402091
308
-
309
- @example
310
- ```
311
- import type {KeysOfUnion} from 'type-fest';
312
-
313
- type A = {
314
- common: string;
315
- a: number;
316
- };
317
-
318
- type B = {
319
- common: string;
320
- b: string;
321
- };
322
-
323
- type C = {
324
- common: string;
325
- c: boolean;
326
- };
327
-
328
- type Union = A | B | C;
329
-
330
- type CommonKeys = keyof Union;
331
- //=> 'common'
332
-
333
- type AllKeys = KeysOfUnion<Union>;
334
- //=> 'common' | 'a' | 'b' | 'c'
335
- ```
336
-
337
- @group type-fest
338
- */
339
- type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
340
- //#endregion
341
- //#region ../core/src/types/type-fest/optional-keys-of.d.ts
342
- /**
343
- Extract all optional keys from the given type.
344
-
345
- This is useful when you want to create a new type that contains different type values for the optional keys only.
346
-
347
- @example
348
- ```
349
- import type {OptionalKeysOf, Except} from 'type-fest';
350
-
351
- interface User {
352
- name: string;
353
- surname: string;
354
-
355
- luckyNumber?: number;
356
- }
357
-
358
- const REMOVE_FIELD = Symbol('remove field symbol');
359
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
360
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
361
- };
362
-
363
- const update1: UpdateOperation<User> = {
364
- name: 'Alice'
365
- };
366
-
367
- const update2: UpdateOperation<User> = {
368
- name: 'Bob',
369
- luckyNumber: REMOVE_FIELD
370
- };
371
- ```
372
-
373
- @group type-fest
374
- */
375
- type OptionalKeysOf<BaseType extends object> = BaseType extends unknown ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) : never;
376
- //#endregion
377
- //#region ../core/src/types/type-fest/required-keys-of.d.ts
378
- /**
379
- Extract all required keys from the given type.
380
-
381
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
382
-
383
- @example
384
- ```
385
- import type {RequiredKeysOf} from 'type-fest';
386
-
387
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
388
-
389
- interface User {
390
- name: string;
391
- surname: string;
392
-
393
- luckyNumber?: number;
394
- }
395
-
396
- const validator1 = createValidation<User>('name', value => value.length < 25);
397
- const validator2 = createValidation<User>('surname', value => value.length < 25);
398
- ```
399
-
400
- @group type-fest
401
- */
402
- type RequiredKeysOf<BaseType extends object> = BaseType extends unknown ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
403
- //#endregion
404
- //#region ../core/src/types/type-fest/omit-index-signature.d.ts
445
+ //#region ../../node_modules/type-fest/source/omit-index-signature.d.ts
405
446
  /**
406
447
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
407
448
 
@@ -427,13 +468,13 @@ Instead of causing a type error like the above, you can also use a [conditional
427
468
 
428
469
  ```
429
470
  type Indexed = {} extends Record<string, unknown>
430
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
431
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
471
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
472
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
432
473
  // => '✅ `{}` is assignable to `Record<string, unknown>`'
433
474
 
434
475
  type Keyed = {} extends Record<'foo' | 'bar', unknown>
435
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
436
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
476
+ ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
477
+ : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
437
478
  // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
438
479
  ```
439
480
 
@@ -443,8 +484,8 @@ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-type
443
484
  import type {OmitIndexSignature} from 'type-fest';
444
485
 
445
486
  type OmitIndexSignature<ObjectType> = {
446
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
447
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
487
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
488
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
448
489
  };
449
490
  ```
450
491
 
@@ -454,12 +495,12 @@ type OmitIndexSignature<ObjectType> = {
454
495
  import type {OmitIndexSignature} from 'type-fest';
455
496
 
456
497
  type OmitIndexSignature<ObjectType> = {
457
- [KeyType in keyof ObjectType
458
- // Is `{}` assignable to `Record<KeyType, unknown>`?
459
- as {} extends Record<KeyType, unknown>
460
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
461
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
462
- ]: ObjectType[KeyType];
498
+ [KeyType in keyof ObjectType
499
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
500
+ as {} extends Record<KeyType, unknown>
501
+ ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
502
+ : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
503
+ ]: ObjectType[KeyType];
463
504
  };
464
505
  ```
465
506
 
@@ -470,19 +511,19 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
470
511
  import type {OmitIndexSignature} from 'type-fest';
471
512
 
472
513
  interface Example {
473
- // These index signatures will be removed.
474
- [x: string]: any
475
- [x: number]: any
476
- [x: symbol]: any
477
- [x: `head-${string}`]: string
478
- [x: `${string}-tail`]: string
479
- [x: `head-${string}-tail`]: string
480
- [x: `${bigint}`]: string
481
- [x: `embedded-${number}`]: string
482
-
483
- // These explicitly defined keys will remain.
484
- foo: 'bar';
485
- qux?: 'baz';
514
+ // These index signatures will be removed.
515
+ [x: string]: any
516
+ [x: number]: any
517
+ [x: symbol]: any
518
+ [x: `head-${string}`]: string
519
+ [x: `${string}-tail`]: string
520
+ [x: `head-${string}-tail`]: string
521
+ [x: `${bigint}`]: string
522
+ [x: `embedded-${number}`]: string
523
+
524
+ // These explicitly defined keys will remain.
525
+ foo: 'bar';
526
+ qux?: 'baz';
486
527
  }
487
528
 
488
529
  type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
@@ -490,12 +531,11 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
490
531
  ```
491
532
 
492
533
  @see PickIndexSignature
493
-
494
- @group type-fest
534
+ @category Object
495
535
  */
496
536
  type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
497
537
  //#endregion
498
- //#region ../core/src/types/type-fest/pick-index-signature.d.ts
538
+ //#region ../../node_modules/type-fest/source/pick-index-signature.d.ts
499
539
  /**
500
540
  Pick only index signatures from the given object type, leaving out all explicitly defined properties.
501
541
 
@@ -508,21 +548,21 @@ import type {PickIndexSignature} from 'type-fest';
508
548
  declare const symbolKey: unique symbol;
509
549
 
510
550
  type Example = {
511
- // These index signatures will remain.
512
- [x: string]: unknown;
513
- [x: number]: unknown;
514
- [x: symbol]: unknown;
515
- [x: `head-${string}`]: string;
516
- [x: `${string}-tail`]: string;
517
- [x: `head-${string}-tail`]: string;
518
- [x: `${bigint}`]: string;
519
- [x: `embedded-${number}`]: string;
520
-
521
- // These explicitly defined keys will be removed.
522
- ['kebab-case-key']: string;
523
- [symbolKey]: string;
524
- foo: 'bar';
525
- qux?: 'baz';
551
+ // These index signatures will remain.
552
+ [x: string]: unknown;
553
+ [x: number]: unknown;
554
+ [x: symbol]: unknown;
555
+ [x: `head-${string}`]: string;
556
+ [x: `${string}-tail`]: string;
557
+ [x: `head-${string}-tail`]: string;
558
+ [x: `${bigint}`]: string;
559
+ [x: `embedded-${number}`]: string;
560
+
561
+ // These explicitly defined keys will be removed.
562
+ ['kebab-case-key']: string;
563
+ [symbolKey]: string;
564
+ foo: 'bar';
565
+ qux?: 'baz';
526
566
  };
527
567
 
528
568
  type ExampleIndexSignature = PickIndexSignature<Example>;
@@ -539,13 +579,14 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
539
579
  ```
540
580
 
541
581
  @see OmitIndexSignature
542
-
543
- @group type-fest
582
+ @category Object
544
583
  */
545
584
  type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
546
585
  //#endregion
547
- //#region ../core/src/types/type-fest/merge.d.ts
586
+ //#region ../../node_modules/type-fest/source/merge.d.ts
587
+ // Merges two objects without worrying about index signatures.
548
588
  type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
589
+
549
590
  /**
550
591
  Merge two types into a new type. Keys of the second type overrides keys of the first type.
551
592
 
@@ -554,17 +595,17 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
554
595
  import type {Merge} from 'type-fest';
555
596
 
556
597
  interface Foo {
557
- [x: string]: unknown;
558
- [x: number]: unknown;
559
- foo: string;
560
- bar: symbol;
598
+ [x: string]: unknown;
599
+ [x: number]: unknown;
600
+ foo: string;
601
+ bar: symbol;
561
602
  }
562
603
 
563
604
  type Bar = {
564
- [x: number]: number;
565
- [x: symbol]: unknown;
566
- bar: Date;
567
- baz: boolean;
605
+ [x: number]: number;
606
+ [x: symbol]: unknown;
607
+ bar: Date;
608
+ baz: boolean;
568
609
  };
569
610
 
570
611
  export type FooBar = Merge<Foo, Bar>;
@@ -578,11 +619,11 @@ export type FooBar = Merge<Foo, Bar>;
578
619
  // }
579
620
  ```
580
621
 
581
- @group type-fest
622
+ @category Object
582
623
  */
583
624
  type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
584
625
  //#endregion
585
- //#region ../core/src/types/type-fest/if-any.d.ts
626
+ //#region ../../node_modules/type-fest/source/if-any.d.ts
586
627
  /**
587
628
  An if-else-like type that resolves depending on whether the given type is `any`.
588
629
 
@@ -599,11 +640,14 @@ type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
599
640
  //=> 'bar'
600
641
  ```
601
642
 
602
- @group type-fest
643
+ @category Type Guard
644
+ @category Utilities
603
645
  */
604
646
  type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
605
647
  //#endregion
606
- //#region ../core/src/types/type-fest/internal/type.d.ts
648
+ //#region ../../node_modules/type-fest/source/internal/type.d.ts
649
+ // Should never happen
650
+
607
651
  /**
608
652
  An if-else-like type that resolves depending on whether the given type is `any` or `never`.
609
653
 
@@ -621,12 +665,10 @@ type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
621
665
  type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
622
666
  //=> 'IS_NEVER'
623
667
  ```
624
-
625
- @group type-fest
626
668
  */
627
669
  type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever<T> extends true ? IfNever : IfNotAnyOrNever;
628
670
  //#endregion
629
- //#region ../core/src/types/type-fest/internal/object.d.ts
671
+ //#region ../../node_modules/type-fest/source/internal/object.d.ts
630
672
  /**
631
673
  Works similar to the built-in `Pick` utility type, except for the following differences:
632
674
  - Distributes over union types and allows picking keys from any member of the union type.
@@ -637,15 +679,15 @@ Works similar to the built-in `Pick` utility type, except for the following diff
637
679
  @example
638
680
  ```
639
681
  type ImageUpload = {
640
- url: string;
641
- size: number;
642
- thumbnailUrl: string;
682
+ url: string;
683
+ size: number;
684
+ thumbnailUrl: string;
643
685
  };
644
686
 
645
687
  type VideoUpload = {
646
- url: string;
647
- duration: number;
648
- encodingFormat: string;
688
+ url: string;
689
+ duration: number;
690
+ encodingFormat: string;
649
691
  };
650
692
 
651
693
  // Distributes over union types and allows picking keys from any member of the union type
@@ -663,8 +705,6 @@ type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
663
705
  // Doesn't pick `number` from a `string` index signature
664
706
  type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
665
707
  //=> {}
666
-
667
- @group type-fest
668
708
  */
669
709
  type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
670
710
  /**
@@ -718,12 +758,11 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
718
758
  // ~~~~~~~~~~~~~~~~
719
759
  // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
720
760
  ```
721
-
722
- @group type-fest
723
761
  */
724
- 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>>>>;
762
+ 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>`
763
+ >>;
725
764
  //#endregion
726
- //#region ../core/src/types/type-fest/except.d.ts
765
+ //#region ../../node_modules/type-fest/source/except.d.ts
727
766
  /**
728
767
  Filter out keys from an object.
729
768
 
@@ -755,16 +794,15 @@ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ?
755
794
  type ExceptOptions = {
756
795
  /**
757
796
  Disallow assigning non-specified properties.
758
-
759
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
760
-
761
- @default false
797
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
798
+ @default false
762
799
  */
763
800
  requireExactProps?: boolean;
764
801
  };
765
802
  type DefaultExceptOptions = {
766
803
  requireExactProps: false;
767
804
  };
805
+
768
806
  /**
769
807
  Create a type from an object type without certain keys.
770
808
 
@@ -779,8 +817,8 @@ This type was proposed to the TypeScript team, which declined it, saying they pr
779
817
  import type {Except} from 'type-fest';
780
818
 
781
819
  type Foo = {
782
- a: number;
783
- b: string;
820
+ a: number;
821
+ b: string;
784
822
  };
785
823
 
786
824
  type FooWithoutA = Except<Foo, 'a'>;
@@ -800,10 +838,10 @@ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
800
838
  // Consider the following example:
801
839
 
802
840
  type UserData = {
803
- [metadata: string]: string;
804
- email: string;
805
- name: string;
806
- role: 'admin' | 'user';
841
+ [metadata: string]: string;
842
+ email: string;
843
+ name: string;
844
+ role: 'admin' | 'user';
807
845
  };
808
846
 
809
847
  // `Omit` clearly doesn't behave as expected in this case:
@@ -816,12 +854,12 @@ type PostPayload = Except<UserData, 'email'>;
816
854
  //=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
817
855
  ```
818
856
 
819
- @group type-fest
857
+ @category Object
820
858
  */
821
859
  type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
822
- type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options["requireExactProps"] extends true ? Partial<Record<KeysType, never>> : {});
860
+ type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
823
861
  //#endregion
824
- //#region ../core/src/types/type-fest/require-at-least-one.d.ts
862
+ //#region ../../node_modules/type-fest/source/require-at-least-one.d.ts
825
863
  /**
826
864
  Create a type that requires at least one of the given keys. The remaining keys are kept as is.
827
865
 
@@ -830,23 +868,30 @@ Create a type that requires at least one of the given keys. The remaining keys a
830
868
  import type {RequireAtLeastOne} from 'type-fest';
831
869
 
832
870
  type Responder = {
833
- text?: () => string;
834
- json?: () => string;
835
- secure?: boolean;
871
+ text?: () => string;
872
+ json?: () => string;
873
+ secure?: boolean;
836
874
  };
837
875
 
838
876
  const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
839
- json: () => '{"message": "ok"}',
840
- secure: true
877
+ json: () => '{"message": "ok"}',
878
+ secure: true
841
879
  };
842
880
  ```
843
881
 
844
- @group type-fest
882
+ @category Object
845
883
  */
846
884
  type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, never, _RequireAtLeastOne<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
847
- type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]-?: Required<Pick<ObjectType, Key>> & Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] & Except<ObjectType, KeysType>;
885
+ type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = {
886
+ // For each `Key` in `KeysType` make a mapped type:
887
+ [Key in KeysType]-?: Required<Pick<ObjectType, Key>> &
888
+ // 1. Make `Key`'s type required
889
+ // 2. Make all other keys in `KeysType` optional
890
+ Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] &
891
+ // 3. Add the remaining keys not in `KeysType`
892
+ Except<ObjectType, KeysType>;
848
893
  //#endregion
849
- //#region ../core/src/types/type-fest/set-required.d.ts
894
+ //#region ../../node_modules/type-fest/source/set-required.d.ts
850
895
  /**
851
896
  Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
852
897
 
@@ -857,9 +902,9 @@ Use-case: You want to define a single model where the only thing that changes is
857
902
  import type {SetRequired} from 'type-fest';
858
903
 
859
904
  type Foo = {
860
- a?: number;
861
- b: string;
862
- c?: boolean;
905
+ a?: number;
906
+ b: string;
907
+ c?: boolean;
863
908
  }
864
909
 
865
910
  type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
@@ -874,13 +919,27 @@ type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
874
919
  //=> [number, number, number?]
875
920
  ```
876
921
 
877
- @group type-fest
922
+ @category Object
878
923
  */
879
- type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<Except<BaseType, Keys> & Required<HomomorphicPick<BaseType, Keys>>>;
924
+ type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<
925
+ // Pick just the keys that are optional from the base type.
926
+ Except<BaseType, Keys> &
927
+ // Pick the keys that should be required from the base type and make them required.
928
+ Required<HomomorphicPick<BaseType, Keys>>>;
880
929
  /**
881
930
  Remove the optional modifier from the specified keys in an array.
882
931
  */
883
- type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown ? keyof TArray & `${number}` extends never ? [...Accumulator, ...TArray] : TArray extends readonly [(infer First)?, ...infer Rest] ? "0" extends OptionalKeysOf<TArray> ? `${Counter["length"]}` extends `${Keys & (string | number)}` ? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]> : [...Accumulator, ...TArray] : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]> : never : never;
932
+ type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown // For distributing `TArray` when it's a union
933
+ ? keyof TArray & `${number}` extends never
934
+ // Exit if `TArray` is empty (e.g., []), or
935
+ // `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
936
+ ? [...Accumulator, ...TArray] : TArray extends readonly [(infer First)?, ...infer Rest] ? '0' extends OptionalKeysOf<TArray> // If the first element of `TArray` is optional
937
+ ? `${Counter['length']}` extends `${Keys & (string | number)}` // If the current index needs to be required
938
+ ? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]>
939
+ // If the current element is optional, but it doesn't need to be required,
940
+ // then we can exit early, since no further elements can now be made required.
941
+ : [...Accumulator, ...TArray] : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]> : never // Should never happen, since `[(infer F)?, ...infer R]` is a top-type for arrays.
942
+ : never; // Should never happen
884
943
  //#endregion
885
944
  //#region ../core/src/types/options.d.ts
886
945
  /**
@@ -989,6 +1048,12 @@ interface CommonRuleAndGroupProperties {
989
1048
  path?: Path;
990
1049
  id?: string;
991
1050
  disabled?: boolean;
1051
+ /**
1052
+ * Whether this rule or group is muted. When muted, the rule or group
1053
+ * is excluded from query export formats (SQL, JSON, MongoDB, etc.).
1054
+ * For groups, muting recursively mutes all children.
1055
+ */
1056
+ muted?: boolean;
992
1057
  }
993
1058
  /**
994
1059
  * The main rule type. The `field`, `operator`, and `value` properties
@@ -1691,4 +1756,4 @@ type IsDateFieldFunction = (...[rule, opts]: Parameters<RuleProcessor>) => boole
1691
1756
  type IsDateField = IsDateFieldFunction | Record<string, unknown> | Record<string, unknown>[] | boolean | undefined;
1692
1757
  //#endregion
1693
1758
  export { ExportOperatorMap, IsDateField, IsDateFieldFunction, RQBDateTimeJsonLogic, RQBDateTimeLibraryAPI, RQBJsonLogicDateAfter, RQBJsonLogicDateBefore, RQBJsonLogicDateBetween, RQBJsonLogicDateIn, RQBJsonLogicDateNotBetween, RQBJsonLogicDateNotIn, RQBJsonLogicDateNotOn, RQBJsonLogicDateOn, RQBJsonLogicDateOnOrAfter, RQBJsonLogicDateOnOrBefore, RQBJsonLogicDateTimeOperations, RuleProcessor, ValueProcessorByRule };
1694
- //# sourceMappingURL=types-EgfSemtR.d.ts.map
1759
+ //# sourceMappingURL=types-Dm-PhQtt.d.ts.map