@react-querybuilder/core 8.11.2 → 8.13.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.
- package/dist/{basic-CLG_Bmom.d.mts → basic-Cw014pDc.d.mts} +123 -98
- package/dist/{basic-BeKPP0_1.d.ts → basic-_KlsCAyT.d.ts} +123 -98
- package/dist/chunk-U64pC571.js +41 -0
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +215 -148
- package/dist/cjs/react-querybuilder_core.cjs.development.js +28 -37
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +215 -148
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-Cj4t-LT4.mjs → convertQuery-DAj92cbM.mjs} +3 -3
- package/dist/{convertQuery-Cj4t-LT4.mjs.map → convertQuery-DAj92cbM.mjs.map} +1 -1
- package/dist/{convertQuery-C7NvB0XA.js → convertQuery-DRldbzhZ.js} +4 -4
- package/dist/{convertQuery-C7NvB0XA.js.map → convertQuery-DRldbzhZ.js.map} +1 -1
- package/dist/{export-B2Yw5gak.d.mts → export-CffjLxEe.d.mts} +2 -2
- package/dist/{export-CQB0nuvW.d.ts → export-DRA8O1Wz.d.ts} +2 -2
- package/dist/formatQuery.d.mts +2 -2
- package/dist/formatQuery.d.ts +2 -2
- package/dist/formatQuery.js +19 -13
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +18 -12
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-Dvayhrgj.d.ts → import-CWYJkN_w.d.ts} +2 -2
- package/dist/{import-BtpySRSy.d.mts → import-DjHGaGhJ.d.mts} +2 -2
- package/dist/{isRuleGroup-DqAs2x4E.js → isRuleGroup-Cjk1Q2mj.js} +2 -40
- package/dist/{isRuleGroup-DqAs2x4E.js.map → isRuleGroup-Cjk1Q2mj.js.map} +1 -1
- package/dist/{isRuleGroup-BcfwGaIN.mjs → isRuleGroup-DztIOOKa.mjs} +1 -1
- package/dist/{isRuleGroup-BcfwGaIN.mjs.map → isRuleGroup-DztIOOKa.mjs.map} +1 -1
- package/dist/parseCEL.d.mts +2 -2
- package/dist/parseCEL.d.ts +2 -2
- package/dist/parseCEL.js +16 -6
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +15 -4
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +2 -2
- package/dist/parseJSONata.d.ts +2 -2
- package/dist/parseJSONata.js +13 -6
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +3 -3
- package/dist/parseJsonLogic.d.mts +3 -3
- package/dist/parseJsonLogic.d.ts +3 -3
- package/dist/parseJsonLogic.js +4 -4
- package/dist/parseJsonLogic.mjs +4 -4
- package/dist/parseMongoDB.d.mts +2 -2
- package/dist/parseMongoDB.d.ts +2 -2
- package/dist/parseMongoDB.js +5 -5
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +5 -5
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/parseSQL.d.mts +2 -2
- package/dist/parseSQL.d.ts +2 -2
- package/dist/parseSQL.js +4 -5
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +3 -3
- package/dist/parseSpEL.d.mts +2 -2
- package/dist/parseSpEL.d.ts +2 -2
- package/dist/parseSpEL.js +58 -6
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +3 -3
- package/dist/{prepareQueryObjects-BfnyRV5t.mjs → prepareQueryObjects-6Bxx4Bs1.mjs} +3 -3
- package/dist/{prepareQueryObjects-BfnyRV5t.mjs.map → prepareQueryObjects-6Bxx4Bs1.mjs.map} +1 -1
- package/dist/{prepareQueryObjects-Cz_28zYz.js → prepareQueryObjects-CkN0bTKm.js} +4 -4
- package/dist/{prepareQueryObjects-Cz_28zYz.js.map → prepareQueryObjects-CkN0bTKm.js.map} +1 -1
- package/dist/react-querybuilder_core.d.mts +215 -148
- package/dist/react-querybuilder_core.legacy-esm.d.ts +215 -148
- package/dist/react-querybuilder_core.legacy-esm.js +34 -18
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +28 -12
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +215 -148
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/{transformQuery-B4SaTTO-.js → transformQuery-ClBRfnFg.js} +10 -3
- package/dist/{transformQuery-B4SaTTO-.js.map → transformQuery-ClBRfnFg.js.map} +1 -1
- package/dist/{transformQuery-C85j__7e.mjs → transformQuery-DUpbpqjX.mjs} +9 -2
- package/dist/{transformQuery-C85j__7e.mjs.map → transformQuery-DUpbpqjX.mjs.map} +1 -1
- package/dist/transformQuery.d.mts +1 -1
- package/dist/transformQuery.d.ts +1 -1
- package/dist/transformQuery.js +2 -2
- package/dist/transformQuery.mjs +2 -2
- package/dist/{utils-Dkz3Xn2D.js → utils-CR1ToTMW.js} +3 -4
- package/dist/utils-CR1ToTMW.js.map +1 -0
- package/dist/{utils-DxH23QtE.mjs → utils-nQU7WCM9.mjs} +2 -2
- package/dist/utils-nQU7WCM9.mjs.map +1 -0
- package/package.json +12 -11
- package/dist/utils-Dkz3Xn2D.js.map +0 -1
- package/dist/utils-DxH23QtE.mjs.map +0 -1
|
@@ -14,34 +14,6 @@ type Intersection = UnionToIntersection<Union>;
|
|
|
14
14
|
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
A more applicable example which could make its way into your library code follows.
|
|
18
|
-
|
|
19
|
-
@example
|
|
20
|
-
```
|
|
21
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
22
|
-
|
|
23
|
-
class CommandOne {
|
|
24
|
-
commands: {
|
|
25
|
-
a1: () => undefined,
|
|
26
|
-
b1: () => undefined,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
class CommandTwo {
|
|
31
|
-
commands: {
|
|
32
|
-
a2: (argA: string) => undefined,
|
|
33
|
-
b2: (argB: string) => undefined,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
38
|
-
type Union = typeof union;
|
|
39
|
-
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
40
|
-
|
|
41
|
-
type Intersection = UnionToIntersection<Union>;
|
|
42
|
-
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
17
|
@category Type
|
|
46
18
|
*/
|
|
47
19
|
type UnionToIntersection<Union> = (
|
|
@@ -117,8 +89,8 @@ import type {IsAny} from 'type-fest';
|
|
|
117
89
|
const typedObject = {a: 1, b: 2} as const;
|
|
118
90
|
const anyObject: any = {a: 1, b: 2};
|
|
119
91
|
|
|
120
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(
|
|
121
|
-
return
|
|
92
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
93
|
+
return object[key];
|
|
122
94
|
}
|
|
123
95
|
|
|
124
96
|
const typedA = get(typedObject, 'a');
|
|
@@ -143,17 +115,17 @@ This is useful when writing utility types or schema validators that need to diff
|
|
|
143
115
|
```
|
|
144
116
|
import type {IsOptionalKeyOf} from 'type-fest';
|
|
145
117
|
|
|
146
|
-
|
|
118
|
+
type User = {
|
|
147
119
|
name: string;
|
|
148
120
|
surname: string;
|
|
149
121
|
|
|
150
122
|
luckyNumber?: number;
|
|
151
|
-
}
|
|
123
|
+
};
|
|
152
124
|
|
|
153
|
-
|
|
125
|
+
type Admin = {
|
|
154
126
|
name: string;
|
|
155
127
|
surname?: string;
|
|
156
|
-
}
|
|
128
|
+
};
|
|
157
129
|
|
|
158
130
|
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
159
131
|
//=> true
|
|
@@ -186,12 +158,12 @@ This is useful when you want to create a new type that contains different type v
|
|
|
186
158
|
```
|
|
187
159
|
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
188
160
|
|
|
189
|
-
|
|
161
|
+
type User = {
|
|
190
162
|
name: string;
|
|
191
163
|
surname: string;
|
|
192
164
|
|
|
193
165
|
luckyNumber?: number;
|
|
194
|
-
}
|
|
166
|
+
};
|
|
195
167
|
|
|
196
168
|
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
197
169
|
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
@@ -199,12 +171,12 @@ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKe
|
|
|
199
171
|
};
|
|
200
172
|
|
|
201
173
|
const update1: UpdateOperation<User> = {
|
|
202
|
-
name: 'Alice'
|
|
174
|
+
name: 'Alice',
|
|
203
175
|
};
|
|
204
176
|
|
|
205
177
|
const update2: UpdateOperation<User> = {
|
|
206
178
|
name: 'Bob',
|
|
207
|
-
luckyNumber: REMOVE_FIELD
|
|
179
|
+
luckyNumber: REMOVE_FIELD,
|
|
208
180
|
};
|
|
209
181
|
```
|
|
210
182
|
|
|
@@ -224,17 +196,23 @@ This is useful when you want to create a new type that contains different type v
|
|
|
224
196
|
```
|
|
225
197
|
import type {RequiredKeysOf} from 'type-fest';
|
|
226
198
|
|
|
227
|
-
declare function createValidation<
|
|
199
|
+
declare function createValidation<
|
|
200
|
+
Entity extends object,
|
|
201
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
202
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
228
203
|
|
|
229
|
-
|
|
204
|
+
type User = {
|
|
230
205
|
name: string;
|
|
231
206
|
surname: string;
|
|
232
|
-
|
|
233
207
|
luckyNumber?: number;
|
|
234
|
-
}
|
|
208
|
+
};
|
|
235
209
|
|
|
236
210
|
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
237
211
|
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
212
|
+
|
|
213
|
+
// @ts-expect-error
|
|
214
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
215
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
238
216
|
```
|
|
239
217
|
|
|
240
218
|
@category Utilities
|
|
@@ -256,29 +234,41 @@ Useful in type utilities, such as checking if something does not occur.
|
|
|
256
234
|
```
|
|
257
235
|
import type {IsNever, And} from 'type-fest';
|
|
258
236
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
And<
|
|
262
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
263
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
264
|
-
>;
|
|
265
|
-
|
|
266
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
267
|
-
AreStringsEqual<I, O> extends true
|
|
268
|
-
? never
|
|
269
|
-
: void;
|
|
270
|
-
|
|
271
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
272
|
-
if (input === output) {
|
|
273
|
-
process.exit(0);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
237
|
+
type A = IsNever<never>;
|
|
238
|
+
//=> true
|
|
276
239
|
|
|
277
|
-
|
|
278
|
-
//=>
|
|
240
|
+
type B = IsNever<any>;
|
|
241
|
+
//=> false
|
|
242
|
+
|
|
243
|
+
type C = IsNever<unknown>;
|
|
244
|
+
//=> false
|
|
245
|
+
|
|
246
|
+
type D = IsNever<never[]>;
|
|
247
|
+
//=> false
|
|
248
|
+
|
|
249
|
+
type E = IsNever<object>;
|
|
250
|
+
//=> false
|
|
251
|
+
|
|
252
|
+
type F = IsNever<string>;
|
|
253
|
+
//=> false
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
@example
|
|
257
|
+
```
|
|
258
|
+
import type {IsNever} from 'type-fest';
|
|
259
|
+
|
|
260
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
279
261
|
|
|
280
|
-
|
|
281
|
-
|
|
262
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
263
|
+
type A = IsTrue<never>;
|
|
264
|
+
// ^? type A = never
|
|
265
|
+
|
|
266
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
267
|
+
type IsTrueFixed<T> =
|
|
268
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
269
|
+
|
|
270
|
+
type B = IsTrueFixed<never>;
|
|
271
|
+
// ^? type B = false
|
|
282
272
|
```
|
|
283
273
|
|
|
284
274
|
@category Type Guard
|
|
@@ -299,7 +289,7 @@ Note:
|
|
|
299
289
|
|
|
300
290
|
@example
|
|
301
291
|
```
|
|
302
|
-
import {If} from 'type-fest';
|
|
292
|
+
import type {If} from 'type-fest';
|
|
303
293
|
|
|
304
294
|
type A = If<true, 'yes', 'no'>;
|
|
305
295
|
//=> 'yes'
|
|
@@ -319,7 +309,7 @@ type E = If<never, 'yes', 'no'>;
|
|
|
319
309
|
|
|
320
310
|
@example
|
|
321
311
|
```
|
|
322
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
312
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
323
313
|
|
|
324
314
|
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
325
315
|
//=> 'not any'
|
|
@@ -330,7 +320,7 @@ type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
|
330
320
|
|
|
331
321
|
@example
|
|
332
322
|
```
|
|
333
|
-
import {If, IsEqual} from 'type-fest';
|
|
323
|
+
import type {If, IsEqual} from 'type-fest';
|
|
334
324
|
|
|
335
325
|
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
336
326
|
|
|
@@ -341,6 +331,41 @@ type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
|
341
331
|
//=> 'not equal'
|
|
342
332
|
```
|
|
343
333
|
|
|
334
|
+
Note: Sometimes using the `If` type can make an implementation non–tail-recursive, which can impact performance. In such cases, it’s better to use a conditional directly. Refer to the following example:
|
|
335
|
+
|
|
336
|
+
@example
|
|
337
|
+
```
|
|
338
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
339
|
+
|
|
340
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
341
|
+
|
|
342
|
+
// The following implementation is not tail recursive
|
|
343
|
+
type Includes<S extends string, Char extends string> =
|
|
344
|
+
S extends `${infer First}${infer Rest}`
|
|
345
|
+
? If<IsEqual<First, Char>,
|
|
346
|
+
'found',
|
|
347
|
+
Includes<Rest, Char>>
|
|
348
|
+
: 'not found';
|
|
349
|
+
|
|
350
|
+
// Hence, instantiations with long strings will fail
|
|
351
|
+
// @ts-expect-error
|
|
352
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
353
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
354
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
355
|
+
|
|
356
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
357
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
358
|
+
S extends `${infer First}${infer Rest}`
|
|
359
|
+
? IsEqual<First, Char> extends true
|
|
360
|
+
? 'found'
|
|
361
|
+
: IncludesWithoutIf<Rest, Char>
|
|
362
|
+
: 'not found';
|
|
363
|
+
|
|
364
|
+
// Now, instantiations with long strings will work
|
|
365
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
366
|
+
//=> 'not found'
|
|
367
|
+
```
|
|
368
|
+
|
|
344
369
|
@category Type Guard
|
|
345
370
|
@category Utilities
|
|
346
371
|
*/
|
|
@@ -426,16 +451,17 @@ const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
|
426
451
|
const someType: SomeType = literal;
|
|
427
452
|
const someInterface: SomeInterface = literal;
|
|
428
453
|
|
|
429
|
-
function fn(object: Record<string, unknown>): void
|
|
454
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
430
455
|
|
|
431
456
|
fn(literal); // Good: literal object type is sealed
|
|
432
457
|
fn(someType); // Good: type is sealed
|
|
458
|
+
// @ts-expect-error
|
|
433
459
|
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
434
460
|
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
435
461
|
```
|
|
436
462
|
|
|
437
463
|
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
438
|
-
@see SimplifyDeep
|
|
464
|
+
@see {@link SimplifyDeep}
|
|
439
465
|
@category Object
|
|
440
466
|
*/
|
|
441
467
|
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
@@ -467,7 +493,7 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
467
493
|
@category Type Guard
|
|
468
494
|
@category Utilities
|
|
469
495
|
*/
|
|
470
|
-
type IsEqual<A, B> = [A
|
|
496
|
+
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
471
497
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
472
498
|
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
473
499
|
//#endregion
|
|
@@ -489,6 +515,7 @@ It relies on the fact that an empty object (`{}`) is assignable to an object wit
|
|
|
489
515
|
```
|
|
490
516
|
const indexed: Record<string, unknown> = {}; // Allowed
|
|
491
517
|
|
|
518
|
+
// @ts-expect-error
|
|
492
519
|
const keyed: Record<'foo', unknown> = {}; // Error
|
|
493
520
|
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
494
521
|
```
|
|
@@ -502,16 +529,14 @@ type Indexed = {} extends Record<string, unknown>
|
|
|
502
529
|
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
503
530
|
|
|
504
531
|
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
505
|
-
?
|
|
506
|
-
:
|
|
532
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
533
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
507
534
|
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
508
535
|
```
|
|
509
536
|
|
|
510
537
|
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
511
538
|
|
|
512
539
|
```
|
|
513
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
514
|
-
|
|
515
540
|
type OmitIndexSignature<ObjectType> = {
|
|
516
541
|
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
517
542
|
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
@@ -521,14 +546,12 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
521
546
|
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
522
547
|
|
|
523
548
|
```
|
|
524
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
525
|
-
|
|
526
549
|
type OmitIndexSignature<ObjectType> = {
|
|
527
550
|
[KeyType in keyof ObjectType
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
551
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
552
|
+
as {} extends Record<KeyType, unknown>
|
|
553
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
554
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
532
555
|
]: ObjectType[KeyType];
|
|
533
556
|
};
|
|
534
557
|
```
|
|
@@ -539,27 +562,27 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
|
|
|
539
562
|
```
|
|
540
563
|
import type {OmitIndexSignature} from 'type-fest';
|
|
541
564
|
|
|
542
|
-
|
|
565
|
+
type Example = {
|
|
543
566
|
// These index signatures will be removed.
|
|
544
|
-
[x: string]: any
|
|
545
|
-
[x: number]: any
|
|
546
|
-
[x: symbol]: any
|
|
547
|
-
[x: `head-${string}`]: string
|
|
548
|
-
[x: `${string}-tail`]: string
|
|
549
|
-
[x: `head-${string}-tail`]: string
|
|
550
|
-
[x: `${bigint}`]: string
|
|
551
|
-
[x: `embedded-${number}`]: string
|
|
567
|
+
[x: string]: any;
|
|
568
|
+
[x: number]: any;
|
|
569
|
+
[x: symbol]: any;
|
|
570
|
+
[x: `head-${string}`]: string;
|
|
571
|
+
[x: `${string}-tail`]: string;
|
|
572
|
+
[x: `head-${string}-tail`]: string;
|
|
573
|
+
[x: `${bigint}`]: string;
|
|
574
|
+
[x: `embedded-${number}`]: string;
|
|
552
575
|
|
|
553
576
|
// These explicitly defined keys will remain.
|
|
554
577
|
foo: 'bar';
|
|
555
578
|
qux?: 'baz';
|
|
556
|
-
}
|
|
579
|
+
};
|
|
557
580
|
|
|
558
581
|
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
559
582
|
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
560
583
|
```
|
|
561
584
|
|
|
562
|
-
@see PickIndexSignature
|
|
585
|
+
@see {@link PickIndexSignature}
|
|
563
586
|
@category Object
|
|
564
587
|
*/
|
|
565
588
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
@@ -607,7 +630,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
607
630
|
// }
|
|
608
631
|
```
|
|
609
632
|
|
|
610
|
-
@see OmitIndexSignature
|
|
633
|
+
@see {@link OmitIndexSignature}
|
|
611
634
|
@category Object
|
|
612
635
|
*/
|
|
613
636
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
@@ -623,12 +646,12 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
|
|
|
623
646
|
```
|
|
624
647
|
import type {Merge} from 'type-fest';
|
|
625
648
|
|
|
626
|
-
|
|
649
|
+
type Foo = {
|
|
627
650
|
[x: string]: unknown;
|
|
628
651
|
[x: number]: unknown;
|
|
629
652
|
foo: string;
|
|
630
653
|
bar: symbol;
|
|
631
|
-
}
|
|
654
|
+
};
|
|
632
655
|
|
|
633
656
|
type Bar = {
|
|
634
657
|
[x: number]: number;
|
|
@@ -807,12 +830,14 @@ type Foo = {
|
|
|
807
830
|
type FooWithoutA = Except<Foo, 'a'>;
|
|
808
831
|
//=> {b: string}
|
|
809
832
|
|
|
833
|
+
// @ts-expect-error
|
|
810
834
|
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
811
835
|
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
812
836
|
|
|
813
837
|
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
814
838
|
//=> {a: number} & Partial<Record<"b", never>>
|
|
815
839
|
|
|
840
|
+
// @ts-expect-error
|
|
816
841
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
817
842
|
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
818
843
|
|
|
@@ -829,12 +854,12 @@ type UserData = {
|
|
|
829
854
|
|
|
830
855
|
// `Omit` clearly doesn't behave as expected in this case:
|
|
831
856
|
type PostPayload = Omit<UserData, 'email'>;
|
|
832
|
-
//=>
|
|
857
|
+
//=> { [x: string]: string; [x: number]: string; }
|
|
833
858
|
|
|
834
859
|
// In situations like this, `Except` works better.
|
|
835
860
|
// It simply removes the `email` key while preserving all the other keys.
|
|
836
|
-
type
|
|
837
|
-
//=>
|
|
861
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
862
|
+
//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
838
863
|
```
|
|
839
864
|
|
|
840
865
|
@category Object
|
|
@@ -856,7 +881,7 @@ type Foo = {
|
|
|
856
881
|
a?: number;
|
|
857
882
|
b: string;
|
|
858
883
|
c?: boolean;
|
|
859
|
-
}
|
|
884
|
+
};
|
|
860
885
|
|
|
861
886
|
type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
|
|
862
887
|
// type SomeRequired = {
|
|
@@ -1254,4 +1279,4 @@ type ParseNumbersModerationLevel = "-limited" | "";
|
|
|
1254
1279
|
type ParseNumbersPropConfig = boolean | `${ParseNumberMethodName}${ParseNumbersModerationLevel}`;
|
|
1255
1280
|
//#endregion
|
|
1256
1281
|
export { Except as C, SetRequired as S, RuleGroupType as _, ValueSource as a, FullOptionList as b, RuleValidator as c, DefaultRuleGroupTypeIC as d, RuleGroupTypeAny as f, DefaultRuleGroupType as g, DefaultOperatorName as h, ParseNumbersPropConfig as i, ValidationMap as l, DefaultCombinatorName as m, FullOperator as n, ValueSources as o, RuleGroupTypeIC as p, InputType as r, QueryValidator as s, FullField as t, ValidationResult as u, RuleType as v, OptionList as x, FlexibleOptionList as y };
|
|
1257
|
-
//# sourceMappingURL=basic-
|
|
1282
|
+
//# sourceMappingURL=basic-Cw014pDc.d.mts.map
|