@regle/core 1.0.0 → 1.0.2
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/regle-core.d.cts +495 -19
- package/dist/regle-core.d.ts +495 -19
- package/package.json +7 -7
package/dist/regle-core.d.cts
CHANGED
|
@@ -4,6 +4,8 @@ type Prettify<T> = T extends infer R ? {
|
|
|
4
4
|
[K in keyof R]: R[K];
|
|
5
5
|
} & {} : never;
|
|
6
6
|
type Maybe<T = any> = T | null | undefined;
|
|
7
|
+
type MaybeInput<T = any> = T | null | undefined;
|
|
8
|
+
type MaybeOutput<T = any> = T | undefined;
|
|
7
9
|
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
8
10
|
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
|
|
9
11
|
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
@@ -137,6 +139,36 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
137
139
|
*/
|
|
138
140
|
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
Extract all required keys from the given type.
|
|
144
|
+
|
|
145
|
+
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...
|
|
146
|
+
|
|
147
|
+
@example
|
|
148
|
+
```
|
|
149
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
150
|
+
|
|
151
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
152
|
+
|
|
153
|
+
interface User {
|
|
154
|
+
name: string;
|
|
155
|
+
surname: string;
|
|
156
|
+
|
|
157
|
+
luckyNumber?: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
161
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
@category Utilities
|
|
165
|
+
*/
|
|
166
|
+
type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
167
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
|
|
168
|
+
? Key
|
|
169
|
+
: never
|
|
170
|
+
}[keyof BaseType], undefined>;
|
|
171
|
+
|
|
140
172
|
/**
|
|
141
173
|
Returns a boolean for whether the given type is `never`.
|
|
142
174
|
|
|
@@ -180,11 +212,381 @@ endIfEqual('abc', '123');
|
|
|
180
212
|
*/
|
|
181
213
|
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
182
214
|
|
|
215
|
+
/**
|
|
216
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
217
|
+
|
|
218
|
+
@see {@link IsNever}
|
|
219
|
+
|
|
220
|
+
@example
|
|
221
|
+
```
|
|
222
|
+
import type {IfNever} from 'type-fest';
|
|
223
|
+
|
|
224
|
+
type ShouldBeTrue = IfNever<never>;
|
|
225
|
+
//=> true
|
|
226
|
+
|
|
227
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
228
|
+
//=> 'bar'
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
@category Type Guard
|
|
232
|
+
@category Utilities
|
|
233
|
+
*/
|
|
234
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
235
|
+
IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
239
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
240
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
Returns a boolean for whether the given type is `any`.
|
|
244
|
+
|
|
245
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
246
|
+
|
|
247
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
248
|
+
|
|
249
|
+
@example
|
|
250
|
+
```
|
|
251
|
+
import type {IsAny} from 'type-fest';
|
|
252
|
+
|
|
253
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
254
|
+
const anyObject: any = {a: 1, b: 2};
|
|
255
|
+
|
|
256
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
257
|
+
return obj[key];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const typedA = get(typedObject, 'a');
|
|
261
|
+
//=> 1
|
|
262
|
+
|
|
263
|
+
const anyA = get(anyObject, 'a');
|
|
264
|
+
//=> any
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
@category Type Guard
|
|
268
|
+
@category Utilities
|
|
269
|
+
*/
|
|
270
|
+
type IsAny$1<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
271
|
+
|
|
183
272
|
/**
|
|
184
273
|
Disallows any of the given keys.
|
|
185
274
|
*/
|
|
186
275
|
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
187
276
|
|
|
277
|
+
/**
|
|
278
|
+
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.
|
|
279
|
+
|
|
280
|
+
@example
|
|
281
|
+
```
|
|
282
|
+
import type {Simplify} from 'type-fest';
|
|
283
|
+
|
|
284
|
+
type PositionProps = {
|
|
285
|
+
top: number;
|
|
286
|
+
left: number;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
type SizeProps = {
|
|
290
|
+
width: number;
|
|
291
|
+
height: number;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
295
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
299
|
+
|
|
300
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
301
|
+
|
|
302
|
+
@example
|
|
303
|
+
```
|
|
304
|
+
import type {Simplify} from 'type-fest';
|
|
305
|
+
|
|
306
|
+
interface SomeInterface {
|
|
307
|
+
foo: number;
|
|
308
|
+
bar?: string;
|
|
309
|
+
baz: number | undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
type SomeType = {
|
|
313
|
+
foo: number;
|
|
314
|
+
bar?: string;
|
|
315
|
+
baz: number | undefined;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
319
|
+
const someType: SomeType = literal;
|
|
320
|
+
const someInterface: SomeInterface = literal;
|
|
321
|
+
|
|
322
|
+
function fn(object: Record<string, unknown>): void {}
|
|
323
|
+
|
|
324
|
+
fn(literal); // Good: literal object type is sealed
|
|
325
|
+
fn(someType); // Good: type is sealed
|
|
326
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
327
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
331
|
+
@see SimplifyDeep
|
|
332
|
+
@category Object
|
|
333
|
+
*/
|
|
334
|
+
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
338
|
+
|
|
339
|
+
This is the counterpart of `PickIndexSignature`.
|
|
340
|
+
|
|
341
|
+
Use-cases:
|
|
342
|
+
- Remove overly permissive signatures from third-party types.
|
|
343
|
+
|
|
344
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
345
|
+
|
|
346
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
347
|
+
|
|
348
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
352
|
+
|
|
353
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
354
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
type Indexed = {} extends Record<string, unknown>
|
|
361
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
362
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
363
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
364
|
+
|
|
365
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
366
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
367
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
368
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
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`...
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
375
|
+
|
|
376
|
+
type OmitIndexSignature<ObjectType> = {
|
|
377
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
378
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
383
|
+
|
|
384
|
+
```
|
|
385
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
386
|
+
|
|
387
|
+
type OmitIndexSignature<ObjectType> = {
|
|
388
|
+
[KeyType in keyof ObjectType
|
|
389
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
390
|
+
as {} extends Record<KeyType, unknown>
|
|
391
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
392
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
393
|
+
]: ObjectType[KeyType];
|
|
394
|
+
};
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
398
|
+
|
|
399
|
+
@example
|
|
400
|
+
```
|
|
401
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
402
|
+
|
|
403
|
+
interface Example {
|
|
404
|
+
// These index signatures will be removed.
|
|
405
|
+
[x: string]: any
|
|
406
|
+
[x: number]: any
|
|
407
|
+
[x: symbol]: any
|
|
408
|
+
[x: `head-${string}`]: string
|
|
409
|
+
[x: `${string}-tail`]: string
|
|
410
|
+
[x: `head-${string}-tail`]: string
|
|
411
|
+
[x: `${bigint}`]: string
|
|
412
|
+
[x: `embedded-${number}`]: string
|
|
413
|
+
|
|
414
|
+
// These explicitly defined keys will remain.
|
|
415
|
+
foo: 'bar';
|
|
416
|
+
qux?: 'baz';
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
420
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
@see PickIndexSignature
|
|
424
|
+
@category Object
|
|
425
|
+
*/
|
|
426
|
+
type OmitIndexSignature<ObjectType> = {
|
|
427
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
428
|
+
? never
|
|
429
|
+
: KeyType]: ObjectType[KeyType];
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
434
|
+
|
|
435
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
436
|
+
|
|
437
|
+
@example
|
|
438
|
+
```
|
|
439
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
440
|
+
|
|
441
|
+
declare const symbolKey: unique symbol;
|
|
442
|
+
|
|
443
|
+
type Example = {
|
|
444
|
+
// These index signatures will remain.
|
|
445
|
+
[x: string]: unknown;
|
|
446
|
+
[x: number]: unknown;
|
|
447
|
+
[x: symbol]: unknown;
|
|
448
|
+
[x: `head-${string}`]: string;
|
|
449
|
+
[x: `${string}-tail`]: string;
|
|
450
|
+
[x: `head-${string}-tail`]: string;
|
|
451
|
+
[x: `${bigint}`]: string;
|
|
452
|
+
[x: `embedded-${number}`]: string;
|
|
453
|
+
|
|
454
|
+
// These explicitly defined keys will be removed.
|
|
455
|
+
['kebab-case-key']: string;
|
|
456
|
+
[symbolKey]: string;
|
|
457
|
+
foo: 'bar';
|
|
458
|
+
qux?: 'baz';
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
462
|
+
// {
|
|
463
|
+
// [x: string]: unknown;
|
|
464
|
+
// [x: number]: unknown;
|
|
465
|
+
// [x: symbol]: unknown;
|
|
466
|
+
// [x: `head-${string}`]: string;
|
|
467
|
+
// [x: `${string}-tail`]: string;
|
|
468
|
+
// [x: `head-${string}-tail`]: string;
|
|
469
|
+
// [x: `${bigint}`]: string;
|
|
470
|
+
// [x: `embedded-${number}`]: string;
|
|
471
|
+
// }
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
@see OmitIndexSignature
|
|
475
|
+
@category Object
|
|
476
|
+
*/
|
|
477
|
+
type PickIndexSignature<ObjectType> = {
|
|
478
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
479
|
+
? KeyType
|
|
480
|
+
: never]: ObjectType[KeyType];
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// Merges two objects without worrying about index signatures.
|
|
484
|
+
type SimpleMerge<Destination, Source> = {
|
|
485
|
+
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
486
|
+
} & Source;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
490
|
+
|
|
491
|
+
@example
|
|
492
|
+
```
|
|
493
|
+
import type {Merge} from 'type-fest';
|
|
494
|
+
|
|
495
|
+
interface Foo {
|
|
496
|
+
[x: string]: unknown;
|
|
497
|
+
[x: number]: unknown;
|
|
498
|
+
foo: string;
|
|
499
|
+
bar: symbol;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
type Bar = {
|
|
503
|
+
[x: number]: number;
|
|
504
|
+
[x: symbol]: unknown;
|
|
505
|
+
bar: Date;
|
|
506
|
+
baz: boolean;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
510
|
+
// => {
|
|
511
|
+
// [x: string]: unknown;
|
|
512
|
+
// [x: number]: number;
|
|
513
|
+
// [x: symbol]: unknown;
|
|
514
|
+
// foo: string;
|
|
515
|
+
// bar: Date;
|
|
516
|
+
// baz: boolean;
|
|
517
|
+
// }
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
@category Object
|
|
521
|
+
*/
|
|
522
|
+
type Merge<Destination, Source> =
|
|
523
|
+
Simplify<
|
|
524
|
+
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
525
|
+
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
526
|
+
>;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
530
|
+
|
|
531
|
+
@see {@link IsAny}
|
|
532
|
+
|
|
533
|
+
@example
|
|
534
|
+
```
|
|
535
|
+
import type {IfAny} from 'type-fest';
|
|
536
|
+
|
|
537
|
+
type ShouldBeTrue = IfAny<any>;
|
|
538
|
+
//=> true
|
|
539
|
+
|
|
540
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
541
|
+
//=> 'bar'
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
@category Type Guard
|
|
545
|
+
@category Utilities
|
|
546
|
+
*/
|
|
547
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
548
|
+
IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
Extract all optional keys from the given type.
|
|
553
|
+
|
|
554
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
555
|
+
|
|
556
|
+
@example
|
|
557
|
+
```
|
|
558
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
559
|
+
|
|
560
|
+
interface User {
|
|
561
|
+
name: string;
|
|
562
|
+
surname: string;
|
|
563
|
+
|
|
564
|
+
luckyNumber?: number;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
568
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
569
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const update1: UpdateOperation<User> = {
|
|
573
|
+
name: 'Alice'
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const update2: UpdateOperation<User> = {
|
|
577
|
+
name: 'Bob',
|
|
578
|
+
luckyNumber: REMOVE_FIELD
|
|
579
|
+
};
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
@category Utilities
|
|
583
|
+
*/
|
|
584
|
+
type OptionalKeysOf<BaseType extends object> = Exclude<{
|
|
585
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
|
|
586
|
+
? never
|
|
587
|
+
: Key
|
|
588
|
+
}[keyof BaseType], undefined>;
|
|
589
|
+
|
|
188
590
|
/**
|
|
189
591
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
190
592
|
*/
|
|
@@ -207,6 +609,72 @@ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
|
207
609
|
: true
|
|
208
610
|
: false;
|
|
209
611
|
|
|
612
|
+
/**
|
|
613
|
+
Merges user specified options with default options.
|
|
614
|
+
|
|
615
|
+
@example
|
|
616
|
+
```
|
|
617
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
618
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
619
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
620
|
+
|
|
621
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
622
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
@example
|
|
626
|
+
```
|
|
627
|
+
// Complains if default values are not provided for optional options
|
|
628
|
+
|
|
629
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
630
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
631
|
+
type SpecifiedOptions = {};
|
|
632
|
+
|
|
633
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
634
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
635
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
@example
|
|
639
|
+
```
|
|
640
|
+
// Complains if an option's default type does not conform to the expected type
|
|
641
|
+
|
|
642
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
643
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
644
|
+
type SpecifiedOptions = {};
|
|
645
|
+
|
|
646
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
647
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
648
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
@example
|
|
652
|
+
```
|
|
653
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
654
|
+
|
|
655
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
656
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
657
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
658
|
+
|
|
659
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
660
|
+
// ~~~~~~~~~~~~~~~~
|
|
661
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
662
|
+
```
|
|
663
|
+
*/
|
|
664
|
+
type ApplyDefaultOptions<
|
|
665
|
+
Options extends object,
|
|
666
|
+
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
667
|
+
SpecifiedOptions extends Options,
|
|
668
|
+
> =
|
|
669
|
+
IfAny<SpecifiedOptions, Defaults,
|
|
670
|
+
IfNever<SpecifiedOptions, Defaults,
|
|
671
|
+
Simplify<Merge<Defaults, {
|
|
672
|
+
[Key in keyof SpecifiedOptions
|
|
673
|
+
as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
|
|
674
|
+
]: SpecifiedOptions[Key]
|
|
675
|
+
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
676
|
+
>>;
|
|
677
|
+
|
|
210
678
|
/**
|
|
211
679
|
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
212
680
|
|
|
@@ -315,6 +783,11 @@ type PartialDeepOptions = {
|
|
|
315
783
|
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
316
784
|
};
|
|
317
785
|
|
|
786
|
+
type DefaultPartialDeepOptions = {
|
|
787
|
+
recurseIntoArrays: false;
|
|
788
|
+
allowUndefinedInNonTupleArrays: true;
|
|
789
|
+
};
|
|
790
|
+
|
|
318
791
|
/**
|
|
319
792
|
Create a type from another type with all keys and nested keys set to optional.
|
|
320
793
|
|
|
@@ -364,7 +837,10 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
|
364
837
|
@category Set
|
|
365
838
|
@category Map
|
|
366
839
|
*/
|
|
367
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
840
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
841
|
+
_PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
842
|
+
|
|
843
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
|
|
368
844
|
? T
|
|
369
845
|
: T extends Map<infer KeyType, infer ValueType>
|
|
370
846
|
? PartialMapDeep<KeyType, ValueType, Options>
|
|
@@ -379,8 +855,8 @@ type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIn
|
|
|
379
855
|
? Options['recurseIntoArrays'] extends true
|
|
380
856
|
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
381
857
|
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
382
|
-
? ReadonlyArray<
|
|
383
|
-
: Array<
|
|
858
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
859
|
+
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
384
860
|
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
385
861
|
: T // If they don't opt into array testing, just use the original type
|
|
386
862
|
: PartialObjectDeep<T, Options>
|
|
@@ -389,28 +865,28 @@ type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIn
|
|
|
389
865
|
/**
|
|
390
866
|
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
391
867
|
*/
|
|
392
|
-
type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions
|
|
868
|
+
type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
393
869
|
|
|
394
870
|
/**
|
|
395
871
|
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
396
872
|
*/
|
|
397
|
-
type PartialSetDeep<T, Options extends PartialDeepOptions
|
|
873
|
+
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
398
874
|
|
|
399
875
|
/**
|
|
400
876
|
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
401
877
|
*/
|
|
402
|
-
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions
|
|
878
|
+
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
403
879
|
|
|
404
880
|
/**
|
|
405
881
|
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
406
882
|
*/
|
|
407
|
-
type PartialReadonlySetDeep<T, Options extends PartialDeepOptions
|
|
883
|
+
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
408
884
|
|
|
409
885
|
/**
|
|
410
886
|
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
411
887
|
*/
|
|
412
|
-
type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions
|
|
413
|
-
[KeyType in keyof ObjectType]?:
|
|
888
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
|
|
889
|
+
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
414
890
|
};
|
|
415
891
|
|
|
416
892
|
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
@@ -650,7 +1126,7 @@ type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefi
|
|
|
650
1126
|
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [
|
|
651
1127
|
unknown
|
|
652
1128
|
] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
|
|
653
|
-
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ?
|
|
1129
|
+
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? MaybeOutput<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? NonNullable<TState> : MaybeOutput<TState> : MaybeOutput<TState> : MaybeOutput<TState>;
|
|
654
1130
|
|
|
655
1131
|
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
656
1132
|
/**
|
|
@@ -1219,7 +1695,7 @@ declare enum InternalRuleType {
|
|
|
1219
1695
|
/**
|
|
1220
1696
|
* Returned typed of rules created with `createRule`
|
|
1221
1697
|
* */
|
|
1222
|
-
interface RegleRuleDefinition<TValue extends any =
|
|
1698
|
+
interface RegleRuleDefinition<TValue extends any = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
|
|
1223
1699
|
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
|
|
1224
1700
|
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1225
1701
|
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
@@ -1230,8 +1706,8 @@ interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] =
|
|
|
1230
1706
|
/**
|
|
1231
1707
|
* Rules with params created with `createRules` are callable while being customizable
|
|
1232
1708
|
*/
|
|
1233
|
-
interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> extends RegleRuleCore<
|
|
1234
|
-
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<
|
|
1709
|
+
interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata>, RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> {
|
|
1710
|
+
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TFilteredValue, TParams, TAsync, TMetadata>;
|
|
1235
1711
|
}
|
|
1236
1712
|
type RegleRuleMetadataExtended = {
|
|
1237
1713
|
$valid: boolean;
|
|
@@ -1257,7 +1733,7 @@ type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
|
1257
1733
|
type RegleRuleMetadataConsumer<TValue extends any, TParams extends any[] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
1258
1734
|
$value: Maybe<TValue>;
|
|
1259
1735
|
} & DefaultMetadataProperties & (TParams extends never ? {} : {
|
|
1260
|
-
$params: TParams;
|
|
1736
|
+
$params: [...TParams];
|
|
1261
1737
|
}) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
|
|
1262
1738
|
/**
|
|
1263
1739
|
* Will be used to consumme metadata on related helpers and rule status
|
|
@@ -1278,7 +1754,7 @@ type RegleRuleRaw<TValue extends any = any, TParams extends any[] = [], TAsync e
|
|
|
1278
1754
|
*/
|
|
1279
1755
|
type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> = [TParams] extends [[]] ? RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> : RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
|
|
1280
1756
|
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
1281
|
-
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
1757
|
+
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any[]>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
1282
1758
|
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
1283
1759
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
1284
1760
|
}) | ({
|
|
@@ -1478,13 +1954,13 @@ type $InternalRegleErrorTree = {
|
|
|
1478
1954
|
*/
|
|
1479
1955
|
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
1480
1956
|
type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{
|
|
1481
|
-
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?:
|
|
1957
|
+
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: MaybeOutput<TState[K]>;
|
|
1482
1958
|
} & {
|
|
1483
1959
|
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? K : TState[K] extends Array<any> ? K : never]: NonNullable<TState[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState[K]>;
|
|
1484
1960
|
}>;
|
|
1485
1961
|
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any>> = {
|
|
1486
1962
|
valid: false;
|
|
1487
|
-
data: NonNullable<Data> extends Date | File ?
|
|
1963
|
+
data: NonNullable<Data> extends Date | File ? MaybeOutput<Data> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data>;
|
|
1488
1964
|
} | {
|
|
1489
1965
|
valid: true;
|
|
1490
1966
|
data: Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules>;
|
|
@@ -1722,7 +2198,7 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata exte
|
|
|
1722
2198
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
1723
2199
|
readonly $params?: any[];
|
|
1724
2200
|
} : {
|
|
1725
|
-
readonly $params: TParams;
|
|
2201
|
+
readonly $params: [...TParams];
|
|
1726
2202
|
});
|
|
1727
2203
|
/**
|
|
1728
2204
|
* @internal
|
|
@@ -1936,4 +2412,4 @@ declare const useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
|
|
|
1936
2412
|
namespace?: MaybeRefOrGetter<string>;
|
|
1937
2413
|
}>;
|
|
1938
2414
|
|
|
1939
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MergedRegles, type MismatchInfo, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, 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 RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };
|
|
2415
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MergedRegles, type MismatchInfo, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, 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 RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };
|
package/dist/regle-core.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ type Prettify<T> = T extends infer R ? {
|
|
|
4
4
|
[K in keyof R]: R[K];
|
|
5
5
|
} & {} : never;
|
|
6
6
|
type Maybe<T = any> = T | null | undefined;
|
|
7
|
+
type MaybeInput<T = any> = T | null | undefined;
|
|
8
|
+
type MaybeOutput<T = any> = T | undefined;
|
|
7
9
|
type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
|
|
8
10
|
type MaybeGetter<T, V = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V>, index: number) => T & TAdd);
|
|
9
11
|
type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
@@ -137,6 +139,36 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
137
139
|
*/
|
|
138
140
|
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
139
141
|
|
|
142
|
+
/**
|
|
143
|
+
Extract all required keys from the given type.
|
|
144
|
+
|
|
145
|
+
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...
|
|
146
|
+
|
|
147
|
+
@example
|
|
148
|
+
```
|
|
149
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
150
|
+
|
|
151
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
152
|
+
|
|
153
|
+
interface User {
|
|
154
|
+
name: string;
|
|
155
|
+
surname: string;
|
|
156
|
+
|
|
157
|
+
luckyNumber?: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
161
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
@category Utilities
|
|
165
|
+
*/
|
|
166
|
+
type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
167
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
|
|
168
|
+
? Key
|
|
169
|
+
: never
|
|
170
|
+
}[keyof BaseType], undefined>;
|
|
171
|
+
|
|
140
172
|
/**
|
|
141
173
|
Returns a boolean for whether the given type is `never`.
|
|
142
174
|
|
|
@@ -180,11 +212,381 @@ endIfEqual('abc', '123');
|
|
|
180
212
|
*/
|
|
181
213
|
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
182
214
|
|
|
215
|
+
/**
|
|
216
|
+
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
217
|
+
|
|
218
|
+
@see {@link IsNever}
|
|
219
|
+
|
|
220
|
+
@example
|
|
221
|
+
```
|
|
222
|
+
import type {IfNever} from 'type-fest';
|
|
223
|
+
|
|
224
|
+
type ShouldBeTrue = IfNever<never>;
|
|
225
|
+
//=> true
|
|
226
|
+
|
|
227
|
+
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
228
|
+
//=> 'bar'
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
@category Type Guard
|
|
232
|
+
@category Utilities
|
|
233
|
+
*/
|
|
234
|
+
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
235
|
+
IsNever$1<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
236
|
+
);
|
|
237
|
+
|
|
238
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
239
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
240
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
Returns a boolean for whether the given type is `any`.
|
|
244
|
+
|
|
245
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
246
|
+
|
|
247
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
248
|
+
|
|
249
|
+
@example
|
|
250
|
+
```
|
|
251
|
+
import type {IsAny} from 'type-fest';
|
|
252
|
+
|
|
253
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
254
|
+
const anyObject: any = {a: 1, b: 2};
|
|
255
|
+
|
|
256
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
257
|
+
return obj[key];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const typedA = get(typedObject, 'a');
|
|
261
|
+
//=> 1
|
|
262
|
+
|
|
263
|
+
const anyA = get(anyObject, 'a');
|
|
264
|
+
//=> any
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
@category Type Guard
|
|
268
|
+
@category Utilities
|
|
269
|
+
*/
|
|
270
|
+
type IsAny$1<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
271
|
+
|
|
183
272
|
/**
|
|
184
273
|
Disallows any of the given keys.
|
|
185
274
|
*/
|
|
186
275
|
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
187
276
|
|
|
277
|
+
/**
|
|
278
|
+
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.
|
|
279
|
+
|
|
280
|
+
@example
|
|
281
|
+
```
|
|
282
|
+
import type {Simplify} from 'type-fest';
|
|
283
|
+
|
|
284
|
+
type PositionProps = {
|
|
285
|
+
top: number;
|
|
286
|
+
left: number;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
type SizeProps = {
|
|
290
|
+
width: number;
|
|
291
|
+
height: number;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
295
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
299
|
+
|
|
300
|
+
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
301
|
+
|
|
302
|
+
@example
|
|
303
|
+
```
|
|
304
|
+
import type {Simplify} from 'type-fest';
|
|
305
|
+
|
|
306
|
+
interface SomeInterface {
|
|
307
|
+
foo: number;
|
|
308
|
+
bar?: string;
|
|
309
|
+
baz: number | undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
type SomeType = {
|
|
313
|
+
foo: number;
|
|
314
|
+
bar?: string;
|
|
315
|
+
baz: number | undefined;
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
319
|
+
const someType: SomeType = literal;
|
|
320
|
+
const someInterface: SomeInterface = literal;
|
|
321
|
+
|
|
322
|
+
function fn(object: Record<string, unknown>): void {}
|
|
323
|
+
|
|
324
|
+
fn(literal); // Good: literal object type is sealed
|
|
325
|
+
fn(someType); // Good: type is sealed
|
|
326
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
327
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
331
|
+
@see SimplifyDeep
|
|
332
|
+
@category Object
|
|
333
|
+
*/
|
|
334
|
+
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
338
|
+
|
|
339
|
+
This is the counterpart of `PickIndexSignature`.
|
|
340
|
+
|
|
341
|
+
Use-cases:
|
|
342
|
+
- Remove overly permissive signatures from third-party types.
|
|
343
|
+
|
|
344
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
345
|
+
|
|
346
|
+
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
347
|
+
|
|
348
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
352
|
+
|
|
353
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
354
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
358
|
+
|
|
359
|
+
```
|
|
360
|
+
type Indexed = {} extends Record<string, unknown>
|
|
361
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
362
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
363
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
364
|
+
|
|
365
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
366
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
367
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
368
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
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`...
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
375
|
+
|
|
376
|
+
type OmitIndexSignature<ObjectType> = {
|
|
377
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
378
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
379
|
+
};
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
383
|
+
|
|
384
|
+
```
|
|
385
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
386
|
+
|
|
387
|
+
type OmitIndexSignature<ObjectType> = {
|
|
388
|
+
[KeyType in keyof ObjectType
|
|
389
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
390
|
+
as {} extends Record<KeyType, unknown>
|
|
391
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
392
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
393
|
+
]: ObjectType[KeyType];
|
|
394
|
+
};
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
398
|
+
|
|
399
|
+
@example
|
|
400
|
+
```
|
|
401
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
402
|
+
|
|
403
|
+
interface Example {
|
|
404
|
+
// These index signatures will be removed.
|
|
405
|
+
[x: string]: any
|
|
406
|
+
[x: number]: any
|
|
407
|
+
[x: symbol]: any
|
|
408
|
+
[x: `head-${string}`]: string
|
|
409
|
+
[x: `${string}-tail`]: string
|
|
410
|
+
[x: `head-${string}-tail`]: string
|
|
411
|
+
[x: `${bigint}`]: string
|
|
412
|
+
[x: `embedded-${number}`]: string
|
|
413
|
+
|
|
414
|
+
// These explicitly defined keys will remain.
|
|
415
|
+
foo: 'bar';
|
|
416
|
+
qux?: 'baz';
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
420
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
@see PickIndexSignature
|
|
424
|
+
@category Object
|
|
425
|
+
*/
|
|
426
|
+
type OmitIndexSignature<ObjectType> = {
|
|
427
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
428
|
+
? never
|
|
429
|
+
: KeyType]: ObjectType[KeyType];
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
434
|
+
|
|
435
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
436
|
+
|
|
437
|
+
@example
|
|
438
|
+
```
|
|
439
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
440
|
+
|
|
441
|
+
declare const symbolKey: unique symbol;
|
|
442
|
+
|
|
443
|
+
type Example = {
|
|
444
|
+
// These index signatures will remain.
|
|
445
|
+
[x: string]: unknown;
|
|
446
|
+
[x: number]: unknown;
|
|
447
|
+
[x: symbol]: unknown;
|
|
448
|
+
[x: `head-${string}`]: string;
|
|
449
|
+
[x: `${string}-tail`]: string;
|
|
450
|
+
[x: `head-${string}-tail`]: string;
|
|
451
|
+
[x: `${bigint}`]: string;
|
|
452
|
+
[x: `embedded-${number}`]: string;
|
|
453
|
+
|
|
454
|
+
// These explicitly defined keys will be removed.
|
|
455
|
+
['kebab-case-key']: string;
|
|
456
|
+
[symbolKey]: string;
|
|
457
|
+
foo: 'bar';
|
|
458
|
+
qux?: 'baz';
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
462
|
+
// {
|
|
463
|
+
// [x: string]: unknown;
|
|
464
|
+
// [x: number]: unknown;
|
|
465
|
+
// [x: symbol]: unknown;
|
|
466
|
+
// [x: `head-${string}`]: string;
|
|
467
|
+
// [x: `${string}-tail`]: string;
|
|
468
|
+
// [x: `head-${string}-tail`]: string;
|
|
469
|
+
// [x: `${bigint}`]: string;
|
|
470
|
+
// [x: `embedded-${number}`]: string;
|
|
471
|
+
// }
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
@see OmitIndexSignature
|
|
475
|
+
@category Object
|
|
476
|
+
*/
|
|
477
|
+
type PickIndexSignature<ObjectType> = {
|
|
478
|
+
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
479
|
+
? KeyType
|
|
480
|
+
: never]: ObjectType[KeyType];
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// Merges two objects without worrying about index signatures.
|
|
484
|
+
type SimpleMerge<Destination, Source> = {
|
|
485
|
+
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
486
|
+
} & Source;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
490
|
+
|
|
491
|
+
@example
|
|
492
|
+
```
|
|
493
|
+
import type {Merge} from 'type-fest';
|
|
494
|
+
|
|
495
|
+
interface Foo {
|
|
496
|
+
[x: string]: unknown;
|
|
497
|
+
[x: number]: unknown;
|
|
498
|
+
foo: string;
|
|
499
|
+
bar: symbol;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
type Bar = {
|
|
503
|
+
[x: number]: number;
|
|
504
|
+
[x: symbol]: unknown;
|
|
505
|
+
bar: Date;
|
|
506
|
+
baz: boolean;
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
510
|
+
// => {
|
|
511
|
+
// [x: string]: unknown;
|
|
512
|
+
// [x: number]: number;
|
|
513
|
+
// [x: symbol]: unknown;
|
|
514
|
+
// foo: string;
|
|
515
|
+
// bar: Date;
|
|
516
|
+
// baz: boolean;
|
|
517
|
+
// }
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
@category Object
|
|
521
|
+
*/
|
|
522
|
+
type Merge<Destination, Source> =
|
|
523
|
+
Simplify<
|
|
524
|
+
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
525
|
+
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
526
|
+
>;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
530
|
+
|
|
531
|
+
@see {@link IsAny}
|
|
532
|
+
|
|
533
|
+
@example
|
|
534
|
+
```
|
|
535
|
+
import type {IfAny} from 'type-fest';
|
|
536
|
+
|
|
537
|
+
type ShouldBeTrue = IfAny<any>;
|
|
538
|
+
//=> true
|
|
539
|
+
|
|
540
|
+
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
541
|
+
//=> 'bar'
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
@category Type Guard
|
|
545
|
+
@category Utilities
|
|
546
|
+
*/
|
|
547
|
+
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
548
|
+
IsAny$1<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
549
|
+
);
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
Extract all optional keys from the given type.
|
|
553
|
+
|
|
554
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
555
|
+
|
|
556
|
+
@example
|
|
557
|
+
```
|
|
558
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
559
|
+
|
|
560
|
+
interface User {
|
|
561
|
+
name: string;
|
|
562
|
+
surname: string;
|
|
563
|
+
|
|
564
|
+
luckyNumber?: number;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
568
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
569
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
const update1: UpdateOperation<User> = {
|
|
573
|
+
name: 'Alice'
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const update2: UpdateOperation<User> = {
|
|
577
|
+
name: 'Bob',
|
|
578
|
+
luckyNumber: REMOVE_FIELD
|
|
579
|
+
};
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
@category Utilities
|
|
583
|
+
*/
|
|
584
|
+
type OptionalKeysOf<BaseType extends object> = Exclude<{
|
|
585
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
|
|
586
|
+
? never
|
|
587
|
+
: Key
|
|
588
|
+
}[keyof BaseType], undefined>;
|
|
589
|
+
|
|
188
590
|
/**
|
|
189
591
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
190
592
|
*/
|
|
@@ -207,6 +609,72 @@ type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> =
|
|
|
207
609
|
: true
|
|
208
610
|
: false;
|
|
209
611
|
|
|
612
|
+
/**
|
|
613
|
+
Merges user specified options with default options.
|
|
614
|
+
|
|
615
|
+
@example
|
|
616
|
+
```
|
|
617
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
618
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
619
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
620
|
+
|
|
621
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
622
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
@example
|
|
626
|
+
```
|
|
627
|
+
// Complains if default values are not provided for optional options
|
|
628
|
+
|
|
629
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
630
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
631
|
+
type SpecifiedOptions = {};
|
|
632
|
+
|
|
633
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
634
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
635
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
@example
|
|
639
|
+
```
|
|
640
|
+
// Complains if an option's default type does not conform to the expected type
|
|
641
|
+
|
|
642
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
643
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
644
|
+
type SpecifiedOptions = {};
|
|
645
|
+
|
|
646
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
647
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
648
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
@example
|
|
652
|
+
```
|
|
653
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
654
|
+
|
|
655
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
656
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
657
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
658
|
+
|
|
659
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
660
|
+
// ~~~~~~~~~~~~~~~~
|
|
661
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
662
|
+
```
|
|
663
|
+
*/
|
|
664
|
+
type ApplyDefaultOptions<
|
|
665
|
+
Options extends object,
|
|
666
|
+
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
667
|
+
SpecifiedOptions extends Options,
|
|
668
|
+
> =
|
|
669
|
+
IfAny<SpecifiedOptions, Defaults,
|
|
670
|
+
IfNever<SpecifiedOptions, Defaults,
|
|
671
|
+
Simplify<Merge<Defaults, {
|
|
672
|
+
[Key in keyof SpecifiedOptions
|
|
673
|
+
as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
|
|
674
|
+
]: SpecifiedOptions[Key]
|
|
675
|
+
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
676
|
+
>>;
|
|
677
|
+
|
|
210
678
|
/**
|
|
211
679
|
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
212
680
|
|
|
@@ -315,6 +783,11 @@ type PartialDeepOptions = {
|
|
|
315
783
|
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
316
784
|
};
|
|
317
785
|
|
|
786
|
+
type DefaultPartialDeepOptions = {
|
|
787
|
+
recurseIntoArrays: false;
|
|
788
|
+
allowUndefinedInNonTupleArrays: true;
|
|
789
|
+
};
|
|
790
|
+
|
|
318
791
|
/**
|
|
319
792
|
Create a type from another type with all keys and nested keys set to optional.
|
|
320
793
|
|
|
@@ -364,7 +837,10 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
|
364
837
|
@category Set
|
|
365
838
|
@category Map
|
|
366
839
|
*/
|
|
367
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
840
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
841
|
+
_PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
842
|
+
|
|
843
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
|
|
368
844
|
? T
|
|
369
845
|
: T extends Map<infer KeyType, infer ValueType>
|
|
370
846
|
? PartialMapDeep<KeyType, ValueType, Options>
|
|
@@ -379,8 +855,8 @@ type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIn
|
|
|
379
855
|
? Options['recurseIntoArrays'] extends true
|
|
380
856
|
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
381
857
|
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
382
|
-
? ReadonlyArray<
|
|
383
|
-
: Array<
|
|
858
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
859
|
+
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
384
860
|
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
385
861
|
: T // If they don't opt into array testing, just use the original type
|
|
386
862
|
: PartialObjectDeep<T, Options>
|
|
@@ -389,28 +865,28 @@ type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIn
|
|
|
389
865
|
/**
|
|
390
866
|
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
391
867
|
*/
|
|
392
|
-
type PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions
|
|
868
|
+
type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
393
869
|
|
|
394
870
|
/**
|
|
395
871
|
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
396
872
|
*/
|
|
397
|
-
type PartialSetDeep<T, Options extends PartialDeepOptions
|
|
873
|
+
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
398
874
|
|
|
399
875
|
/**
|
|
400
876
|
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
401
877
|
*/
|
|
402
|
-
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions
|
|
878
|
+
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
403
879
|
|
|
404
880
|
/**
|
|
405
881
|
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
406
882
|
*/
|
|
407
|
-
type PartialReadonlySetDeep<T, Options extends PartialDeepOptions
|
|
883
|
+
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
408
884
|
|
|
409
885
|
/**
|
|
410
886
|
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
411
887
|
*/
|
|
412
|
-
type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions
|
|
413
|
-
[KeyType in keyof ObjectType]?:
|
|
888
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
|
|
889
|
+
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
414
890
|
};
|
|
415
891
|
|
|
416
892
|
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
@@ -650,7 +1126,7 @@ type SafeProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefi
|
|
|
650
1126
|
type IsPropertyOutputRequired<TState, TRule extends RegleFormPropertyType<any, any> | undefined> = [
|
|
651
1127
|
unknown
|
|
652
1128
|
] extends [TState] ? unknown : NonNullable<TState> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState> extends Record<string, any> ? NonNullable<TState> : {}, TRule> extends false ? false : true : TRule extends RegleRuleDecl<any, any> ? FieldHaveRequiredRule<TRule> extends false ? false : true : false : false;
|
|
653
|
-
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ?
|
|
1129
|
+
type SafeFieldProperty<TState, TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends RegleRuleDecl<any, any> ? unknown extends TRule['required'] ? MaybeOutput<TState> : TRule['required'] extends undefined ? never : TRule['required'] extends RegleRuleDefinition<any, infer Params, any, any, any> ? Params extends never[] ? NonNullable<TState> : MaybeOutput<TState> : MaybeOutput<TState> : MaybeOutput<TState>;
|
|
654
1130
|
|
|
655
1131
|
type ResetOptions<TState extends unknown> = RequireOneOrNone<{
|
|
656
1132
|
/**
|
|
@@ -1219,7 +1695,7 @@ declare enum InternalRuleType {
|
|
|
1219
1695
|
/**
|
|
1220
1696
|
* Returned typed of rules created with `createRule`
|
|
1221
1697
|
* */
|
|
1222
|
-
interface RegleRuleDefinition<TValue extends any =
|
|
1698
|
+
interface RegleRuleDefinition<TValue extends any = unknown, TParams extends any[] = [], TAsync extends boolean = boolean, TMetaData extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetaData> {
|
|
1223
1699
|
validator: RegleRuleDefinitionProcessor<TFilteredValue, TParams, TAsync extends false ? TMetaData : Promise<TMetaData>>;
|
|
1224
1700
|
message: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => string | string[];
|
|
1225
1701
|
active: (metadata: PossibleRegleRuleMetadataConsumer<TFilteredValue>) => boolean;
|
|
@@ -1230,8 +1706,8 @@ interface RegleRuleDefinition<TValue extends any = any, TParams extends any[] =
|
|
|
1230
1706
|
/**
|
|
1231
1707
|
* Rules with params created with `createRules` are callable while being customizable
|
|
1232
1708
|
*/
|
|
1233
|
-
interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean> extends RegleRuleCore<
|
|
1234
|
-
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<
|
|
1709
|
+
interface RegleRuleWithParamsDefinition<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetadata extends RegleRuleMetadataDefinition = boolean, TFilteredValue extends any = TValue extends Date & File & infer M ? M : TValue> extends RegleRuleCore<TFilteredValue, TParams, TAsync, TMetadata>, RegleInternalRuleDefs<TFilteredValue, TParams, TAsync, TMetadata> {
|
|
1710
|
+
(...params: RegleUniversalParams<TParams>): RegleRuleDefinition<TFilteredValue, TParams, TAsync, TMetadata>;
|
|
1235
1711
|
}
|
|
1236
1712
|
type RegleRuleMetadataExtended = {
|
|
1237
1713
|
$valid: boolean;
|
|
@@ -1257,7 +1733,7 @@ type DefaultMetadataProperties = DefaultMetadataPropertiesCommon & {
|
|
|
1257
1733
|
type RegleRuleMetadataConsumer<TValue extends any, TParams extends any[] = never, TMetadata extends RegleRuleMetadataDefinition = boolean> = {
|
|
1258
1734
|
$value: Maybe<TValue>;
|
|
1259
1735
|
} & DefaultMetadataProperties & (TParams extends never ? {} : {
|
|
1260
|
-
$params: TParams;
|
|
1736
|
+
$params: [...TParams];
|
|
1261
1737
|
}) & (Exclude<TMetadata, boolean> extends RegleRuleMetadataExtended ? TMetadata extends boolean ? Partial<Omit<Exclude<TMetadata, boolean>, '$valid'>> : Omit<Exclude<TMetadata, boolean>, '$valid'> : {});
|
|
1262
1738
|
/**
|
|
1263
1739
|
* Will be used to consumme metadata on related helpers and rule status
|
|
@@ -1278,7 +1754,7 @@ type RegleRuleRaw<TValue extends any = any, TParams extends any[] = [], TAsync e
|
|
|
1278
1754
|
*/
|
|
1279
1755
|
type InferRegleRule<TValue extends any = any, TParams extends any[] = [], TAsync extends boolean = false, TMetaData extends RegleRuleMetadataDefinition = boolean> = [TParams] extends [[]] ? RegleRuleDefinition<TValue, TParams, TAsync, TMetaData> : RegleRuleWithParamsDefinition<TValue, TParams, TAsync, TMetaData>;
|
|
1280
1756
|
type RegleRuleDefinitionProcessor<TValue extends any = any, TParams extends any[] = [], TReturn = any> = (value: Maybe<TValue>, ...params: TParams) => TReturn;
|
|
1281
|
-
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
1757
|
+
type RegleRuleDefinitionWithMetadataProcessor<TValue extends any, TMetadata extends RegleRuleMetadataConsumer<TValue, any[]>, TReturn = any> = ((metadata: TMetadata) => TReturn) | TReturn;
|
|
1282
1758
|
type RegleCollectionRuleDefinition<TValue = any[], TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = (RegleRuleDecl<NonNullable<TValue>, TCustomRules> & {
|
|
1283
1759
|
$each: MaybeGetter<RegleFormPropertyType<ArrayElement<NonNullable<TValue>>, TCustomRules>, ArrayElement<TValue>>;
|
|
1284
1760
|
}) | ({
|
|
@@ -1478,13 +1954,13 @@ type $InternalRegleErrorTree = {
|
|
|
1478
1954
|
*/
|
|
1479
1955
|
type $InternalRegleErrors = $InternalRegleCollectionErrors | string[] | $InternalRegleErrorTree;
|
|
1480
1956
|
type PartialFormState<TState extends Record<string, any>> = [unknown] extends [TState] ? {} : Prettify<{
|
|
1481
|
-
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?:
|
|
1957
|
+
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? never : TState[K] extends Array<any> ? never : K]?: MaybeOutput<TState[K]>;
|
|
1482
1958
|
} & {
|
|
1483
1959
|
[K in keyof TState as ExtendOnlyRealRecord<TState[K]> extends true ? K : TState[K] extends Array<any> ? K : never]: NonNullable<TState[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState[K]>;
|
|
1484
1960
|
}>;
|
|
1485
1961
|
type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules extends ReglePartialRuleTree<any>> = {
|
|
1486
1962
|
valid: false;
|
|
1487
|
-
data: NonNullable<Data> extends Date | File ?
|
|
1963
|
+
data: NonNullable<Data> extends Date | File ? MaybeOutput<Data> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data>;
|
|
1488
1964
|
} | {
|
|
1489
1965
|
valid: true;
|
|
1490
1966
|
data: Data extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules>[] : Data extends Date | File ? SafeFieldProperty<Data, TRules> : Data extends Record<string, any> ? DeepSafeFormState<Data, TRules> : SafeFieldProperty<Data, TRules>;
|
|
@@ -1722,7 +2198,7 @@ type RegleRuleStatus<TValue = any, TParams extends any[] = any[], TMetadata exte
|
|
|
1722
2198
|
} & ([TParams] extends [never[]] ? {} : [unknown[]] extends [TParams] ? {
|
|
1723
2199
|
readonly $params?: any[];
|
|
1724
2200
|
} : {
|
|
1725
|
-
readonly $params: TParams;
|
|
2201
|
+
readonly $params: [...TParams];
|
|
1726
2202
|
});
|
|
1727
2203
|
/**
|
|
1728
2204
|
* @internal
|
|
@@ -1936,4 +2412,4 @@ declare const useScopedRegle: useRegleFn<Partial<AllRulesDeclarations>, never, {
|
|
|
1936
2412
|
namespace?: MaybeRefOrGetter<string>;
|
|
1937
2413
|
}>;
|
|
1938
2414
|
|
|
1939
|
-
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MergedRegles, type MismatchInfo, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, 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 RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };
|
|
2415
|
+
export { type $InternalRegleStatus, type AllRulesDeclarations, type DeepMaybeRef, type DeepReactiveState, type FormRuleDeclaration, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleShortcuts, type InferRegleStatusType, type InlineRuleDeclaration, InternalRuleType, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MergedRegles, type MismatchInfo, type NoInferLegacy, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, 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 RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, createRule, createScopedUseRegle, defineRegleConfig, inferRules, mergeRegles, unwrapRuleParameters, useCollectScope, useRegle, useRootStorage, useScopedRegle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regle/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Headless form validation library for Vue 3",
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"pinia": ">=2.2.5",
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@total-typescript/ts-reset": "0.6.1",
|
|
16
|
-
"@types/node": "22.13.
|
|
17
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
18
|
-
"@typescript-eslint/parser": "8.
|
|
16
|
+
"@types/node": "22.13.13",
|
|
17
|
+
"@typescript-eslint/eslint-plugin": "8.28.0",
|
|
18
|
+
"@typescript-eslint/parser": "8.28.0",
|
|
19
19
|
"@vue/test-utils": "2.4.6",
|
|
20
20
|
"bumpp": "10.1.0",
|
|
21
21
|
"changelogithub": "13.13.0",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"eslint-plugin-vue": "9.31.0",
|
|
26
26
|
"expect-type": "1.2.0",
|
|
27
27
|
"prettier": "3.3.3",
|
|
28
|
-
"tsup": "8.
|
|
29
|
-
"type-fest": "4.
|
|
28
|
+
"tsup": "8.4.0",
|
|
29
|
+
"type-fest": "4.38.0",
|
|
30
30
|
"typescript": "5.6.3",
|
|
31
31
|
"vitest": "3.0.9",
|
|
32
32
|
"vue": "3.5.13",
|
|
33
33
|
"vue-eslint-parser": "9.4.3",
|
|
34
|
-
"vue-tsc": "2.
|
|
34
|
+
"vue-tsc": "2.2.8"
|
|
35
35
|
},
|
|
36
36
|
"type": "module",
|
|
37
37
|
"exports": {
|