@regle/core 1.10.0 → 1.10.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.ts +1263 -7
- package/package.json +1 -1
package/dist/regle-core.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import * as vue0 from "vue";
|
|
2
2
|
import { MaybeRef, MaybeRefOrGetter, Raw, Ref, UnwrapNestedRefs, UnwrapRef } from "vue";
|
|
3
|
-
import { EmptyObject, IsAny, IsEmptyObject, IsUnion, IsUnknown, Merge, Or, PartialDeep, RequireOneOrNone, RequiredDeep, UnionToIntersection, UnionToTuple } from "type-fest";
|
|
4
|
-
import { IsUnion as IsUnion$1 } from "expect-type";
|
|
5
3
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
4
|
|
|
7
5
|
//#region src/types/utils/misc.types.d.ts
|
|
@@ -28,6 +26,1226 @@ type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
|
|
|
28
26
|
type ArrayElement<T> = T extends Array<infer U> ? U : never;
|
|
29
27
|
type NonEmptyTuple<T> = [T, ...T[]] | T[];
|
|
30
28
|
//#endregion
|
|
29
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/primitive.d.ts
|
|
30
|
+
/**
|
|
31
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
32
|
+
|
|
33
|
+
@category Type
|
|
34
|
+
*/
|
|
35
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/union-to-intersection.d.ts
|
|
38
|
+
/**
|
|
39
|
+
Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
40
|
+
|
|
41
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
42
|
+
|
|
43
|
+
@example
|
|
44
|
+
```
|
|
45
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
46
|
+
|
|
47
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
48
|
+
|
|
49
|
+
type Intersection = UnionToIntersection<Union>;
|
|
50
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A more applicable example which could make its way into your library code follows.
|
|
54
|
+
|
|
55
|
+
@example
|
|
56
|
+
```
|
|
57
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
58
|
+
|
|
59
|
+
class CommandOne {
|
|
60
|
+
commands: {
|
|
61
|
+
a1: () => undefined,
|
|
62
|
+
b1: () => undefined,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
class CommandTwo {
|
|
67
|
+
commands: {
|
|
68
|
+
a2: (argA: string) => undefined,
|
|
69
|
+
b2: (argB: string) => undefined,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
74
|
+
type Union = typeof union;
|
|
75
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
76
|
+
|
|
77
|
+
type Intersection = UnionToIntersection<Union>;
|
|
78
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
@category Type
|
|
82
|
+
*/
|
|
83
|
+
type UnionToIntersection<Union> = (
|
|
84
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
85
|
+
// `Union` into a [distributive conditional
|
|
86
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
87
|
+
Union extends unknown
|
|
88
|
+
// The union type is used as the only argument to a function since the union
|
|
89
|
+
// of function arguments is an intersection.
|
|
90
|
+
? (distributedUnion: Union) => void
|
|
91
|
+
// This won't happen.
|
|
92
|
+
: never
|
|
93
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
94
|
+
// arguments of unions of functions as an intersection of the union.
|
|
95
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
96
|
+
// The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
|
|
97
|
+
? Intersection & Union : never;
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/empty-object.d.ts
|
|
100
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
104
|
+
|
|
105
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
106
|
+
|
|
107
|
+
@example
|
|
108
|
+
```
|
|
109
|
+
import type {EmptyObject} from 'type-fest';
|
|
110
|
+
|
|
111
|
+
// The following illustrates the problem with `{}`.
|
|
112
|
+
const foo1: {} = {}; // Pass
|
|
113
|
+
const foo2: {} = []; // Pass
|
|
114
|
+
const foo3: {} = 42; // Pass
|
|
115
|
+
const foo4: {} = {a: 1}; // Pass
|
|
116
|
+
|
|
117
|
+
// With `EmptyObject` only the first case is valid.
|
|
118
|
+
const bar1: EmptyObject = {}; // Pass
|
|
119
|
+
const bar2: EmptyObject = 42; // Fail
|
|
120
|
+
const bar3: EmptyObject = []; // Fail
|
|
121
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
125
|
+
|
|
126
|
+
@category Object
|
|
127
|
+
*/
|
|
128
|
+
type EmptyObject = {
|
|
129
|
+
[emptyObjectSymbol]?: never;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
|
|
133
|
+
|
|
134
|
+
@example
|
|
135
|
+
```
|
|
136
|
+
import type {IsEmptyObject} from 'type-fest';
|
|
137
|
+
|
|
138
|
+
type Pass = IsEmptyObject<{}>; //=> true
|
|
139
|
+
type Fail = IsEmptyObject<[]>; //=> false
|
|
140
|
+
type Fail = IsEmptyObject<null>; //=> false
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
@see {@link EmptyObject}
|
|
144
|
+
@category Object
|
|
145
|
+
*/
|
|
146
|
+
type IsEmptyObject<T> = T extends EmptyObject ? true : false;
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-any.d.ts
|
|
149
|
+
/**
|
|
150
|
+
Returns a boolean for whether the given type is `any`.
|
|
151
|
+
|
|
152
|
+
@link https://stackoverflow.com/a/49928360/1490091
|
|
153
|
+
|
|
154
|
+
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
155
|
+
|
|
156
|
+
@example
|
|
157
|
+
```
|
|
158
|
+
import type {IsAny} from 'type-fest';
|
|
159
|
+
|
|
160
|
+
const typedObject = {a: 1, b: 2} as const;
|
|
161
|
+
const anyObject: any = {a: 1, b: 2};
|
|
162
|
+
|
|
163
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
164
|
+
return obj[key];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const typedA = get(typedObject, 'a');
|
|
168
|
+
//=> 1
|
|
169
|
+
|
|
170
|
+
const anyA = get(anyObject, 'a');
|
|
171
|
+
//=> any
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
@category Type Guard
|
|
175
|
+
@category Utilities
|
|
176
|
+
*/
|
|
177
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
180
|
+
/**
|
|
181
|
+
Returns a boolean for whether the given key is an optional key of type.
|
|
182
|
+
|
|
183
|
+
This is useful when writing utility types or schema validators that need to differentiate `optional` keys.
|
|
184
|
+
|
|
185
|
+
@example
|
|
186
|
+
```
|
|
187
|
+
import type {IsOptionalKeyOf} from 'type-fest';
|
|
188
|
+
|
|
189
|
+
interface User {
|
|
190
|
+
name: string;
|
|
191
|
+
surname: string;
|
|
192
|
+
|
|
193
|
+
luckyNumber?: number;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
interface Admin {
|
|
197
|
+
name: string;
|
|
198
|
+
surname?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
202
|
+
//=> true
|
|
203
|
+
|
|
204
|
+
type T2 = IsOptionalKeyOf<User, 'name'>;
|
|
205
|
+
//=> false
|
|
206
|
+
|
|
207
|
+
type T3 = IsOptionalKeyOf<User, 'name' | 'luckyNumber'>;
|
|
208
|
+
//=> boolean
|
|
209
|
+
|
|
210
|
+
type T4 = IsOptionalKeyOf<User | Admin, 'name'>;
|
|
211
|
+
//=> false
|
|
212
|
+
|
|
213
|
+
type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
214
|
+
//=> boolean
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
@category Type Guard
|
|
218
|
+
@category Utilities
|
|
219
|
+
*/
|
|
220
|
+
type IsOptionalKeyOf<Type extends object, Key$1 extends keyof Type> = IsAny<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
223
|
+
/**
|
|
224
|
+
Extract all optional keys from the given type.
|
|
225
|
+
|
|
226
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
227
|
+
|
|
228
|
+
@example
|
|
229
|
+
```
|
|
230
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
231
|
+
|
|
232
|
+
interface User {
|
|
233
|
+
name: string;
|
|
234
|
+
surname: string;
|
|
235
|
+
|
|
236
|
+
luckyNumber?: number;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
240
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
241
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const update1: UpdateOperation<User> = {
|
|
245
|
+
name: 'Alice'
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const update2: UpdateOperation<User> = {
|
|
249
|
+
name: 'Bob',
|
|
250
|
+
luckyNumber: REMOVE_FIELD
|
|
251
|
+
};
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
@category Utilities
|
|
255
|
+
*/
|
|
256
|
+
type OptionalKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
257
|
+
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
258
|
+
: never;
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-keys-of.d.ts
|
|
261
|
+
/**
|
|
262
|
+
Extract all required keys from the given type.
|
|
263
|
+
|
|
264
|
+
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...
|
|
265
|
+
|
|
266
|
+
@example
|
|
267
|
+
```
|
|
268
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
269
|
+
|
|
270
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
271
|
+
|
|
272
|
+
interface User {
|
|
273
|
+
name: string;
|
|
274
|
+
surname: string;
|
|
275
|
+
|
|
276
|
+
luckyNumber?: number;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
280
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
@category Utilities
|
|
284
|
+
*/
|
|
285
|
+
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
286
|
+
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-never.d.ts
|
|
289
|
+
/**
|
|
290
|
+
Returns a boolean for whether the given type is `never`.
|
|
291
|
+
|
|
292
|
+
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
293
|
+
@link https://stackoverflow.com/a/53984913/10292952
|
|
294
|
+
@link https://www.zhenghao.io/posts/ts-never
|
|
295
|
+
|
|
296
|
+
Useful in type utilities, such as checking if something does not occur.
|
|
297
|
+
|
|
298
|
+
@example
|
|
299
|
+
```
|
|
300
|
+
import type {IsNever, And} from 'type-fest';
|
|
301
|
+
|
|
302
|
+
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
303
|
+
type AreStringsEqual<A extends string, B extends string> =
|
|
304
|
+
And<
|
|
305
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
306
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
307
|
+
>;
|
|
308
|
+
|
|
309
|
+
type EndIfEqual<I extends string, O extends string> =
|
|
310
|
+
AreStringsEqual<I, O> extends true
|
|
311
|
+
? never
|
|
312
|
+
: void;
|
|
313
|
+
|
|
314
|
+
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
315
|
+
if (input === output) {
|
|
316
|
+
process.exit(0);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
endIfEqual('abc', 'abc');
|
|
321
|
+
//=> never
|
|
322
|
+
|
|
323
|
+
endIfEqual('abc', '123');
|
|
324
|
+
//=> void
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
@category Type Guard
|
|
328
|
+
@category Utilities
|
|
329
|
+
*/
|
|
330
|
+
type IsNever$1<T> = [T] extends [never] ? true : false;
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/if.d.ts
|
|
333
|
+
/**
|
|
334
|
+
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
335
|
+
|
|
336
|
+
Use-cases:
|
|
337
|
+
- You can use this in combination with `Is*` types to create an if-else-like experience. For example, `If<IsAny<any>, 'is any', 'not any'>`.
|
|
338
|
+
|
|
339
|
+
Note:
|
|
340
|
+
- Returns a union of if branch and else branch if the given type is `boolean` or `any`. For example, `If<boolean, 'Y', 'N'>` will return `'Y' | 'N'`.
|
|
341
|
+
- Returns the else branch if the given type is `never`. For example, `If<never, 'Y', 'N'>` will return `'N'`.
|
|
342
|
+
|
|
343
|
+
@example
|
|
344
|
+
```
|
|
345
|
+
import {If} from 'type-fest';
|
|
346
|
+
|
|
347
|
+
type A = If<true, 'yes', 'no'>;
|
|
348
|
+
//=> 'yes'
|
|
349
|
+
|
|
350
|
+
type B = If<false, 'yes', 'no'>;
|
|
351
|
+
//=> 'no'
|
|
352
|
+
|
|
353
|
+
type C = If<boolean, 'yes', 'no'>;
|
|
354
|
+
//=> 'yes' | 'no'
|
|
355
|
+
|
|
356
|
+
type D = If<any, 'yes', 'no'>;
|
|
357
|
+
//=> 'yes' | 'no'
|
|
358
|
+
|
|
359
|
+
type E = If<never, 'yes', 'no'>;
|
|
360
|
+
//=> 'no'
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
@example
|
|
364
|
+
```
|
|
365
|
+
import {If, IsAny, IsNever} from 'type-fest';
|
|
366
|
+
|
|
367
|
+
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
368
|
+
//=> 'not any'
|
|
369
|
+
|
|
370
|
+
type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
371
|
+
//=> 'is never'
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
@example
|
|
375
|
+
```
|
|
376
|
+
import {If, IsEqual} from 'type-fest';
|
|
377
|
+
|
|
378
|
+
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
379
|
+
|
|
380
|
+
type A = IfEqual<string, string, 'equal', 'not equal'>;
|
|
381
|
+
//=> 'equal'
|
|
382
|
+
|
|
383
|
+
type B = IfEqual<string, number, 'equal', 'not equal'>;
|
|
384
|
+
//=> 'not equal'
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
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:
|
|
388
|
+
|
|
389
|
+
@example
|
|
390
|
+
```
|
|
391
|
+
import type {If, IsEqual, StringRepeat} from 'type-fest';
|
|
392
|
+
|
|
393
|
+
type HundredZeroes = StringRepeat<'0', 100>;
|
|
394
|
+
|
|
395
|
+
// The following implementation is not tail recursive
|
|
396
|
+
type Includes<S extends string, Char extends string> =
|
|
397
|
+
S extends `${infer First}${infer Rest}`
|
|
398
|
+
? If<IsEqual<First, Char>,
|
|
399
|
+
'found',
|
|
400
|
+
Includes<Rest, Char>>
|
|
401
|
+
: 'not found';
|
|
402
|
+
|
|
403
|
+
// Hence, instantiations with long strings will fail
|
|
404
|
+
// @ts-expect-error
|
|
405
|
+
type Fails = Includes<HundredZeroes, '1'>;
|
|
406
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
407
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
408
|
+
|
|
409
|
+
// However, if we use a simple conditional instead of `If`, the implementation becomes tail-recursive
|
|
410
|
+
type IncludesWithoutIf<S extends string, Char extends string> =
|
|
411
|
+
S extends `${infer First}${infer Rest}`
|
|
412
|
+
? IsEqual<First, Char> extends true
|
|
413
|
+
? 'found'
|
|
414
|
+
: IncludesWithoutIf<Rest, Char>
|
|
415
|
+
: 'not found';
|
|
416
|
+
|
|
417
|
+
// Now, instantiations with long strings will work
|
|
418
|
+
type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
419
|
+
//=> 'not found'
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
@category Type Guard
|
|
423
|
+
@category Utilities
|
|
424
|
+
*/
|
|
425
|
+
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever$1<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/type.d.ts
|
|
428
|
+
/**
|
|
429
|
+
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
430
|
+
*/
|
|
431
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
432
|
+
/**
|
|
433
|
+
Test if the given function has multiple call signatures.
|
|
434
|
+
|
|
435
|
+
Needed to handle the case of a single call signature with properties.
|
|
436
|
+
|
|
437
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
438
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
439
|
+
*/
|
|
440
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
441
|
+
(...arguments_: infer A): unknown;
|
|
442
|
+
(...arguments_: infer B): unknown;
|
|
443
|
+
} ? B extends A ? A extends B ? false : true : true : false;
|
|
444
|
+
/**
|
|
445
|
+
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
446
|
+
|
|
447
|
+
@example
|
|
448
|
+
```
|
|
449
|
+
// When `T` is a NOT `any` or `never` (like `string`) => Returns `IfNotAnyOrNever` branch
|
|
450
|
+
type A = IfNotAnyOrNever<string, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
451
|
+
//=> 'VALID'
|
|
452
|
+
|
|
453
|
+
// When `T` is `any` => Returns `IfAny` branch
|
|
454
|
+
type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
455
|
+
//=> 'IS_ANY'
|
|
456
|
+
|
|
457
|
+
// When `T` is `never` => Returns `IfNever` branch
|
|
458
|
+
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
459
|
+
//=> 'IS_NEVER'
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Note: Wrapping a tail-recursive type with `IfNotAnyOrNever` makes the implementation non-tail-recursive. To fix this, move the recursion into a helper type. Refer to the following example:
|
|
463
|
+
|
|
464
|
+
@example
|
|
465
|
+
```ts
|
|
466
|
+
import type {StringRepeat} from 'type-fest';
|
|
467
|
+
|
|
468
|
+
type NineHundredNinetyNineSpaces = StringRepeat<' ', 999>;
|
|
469
|
+
|
|
470
|
+
// The following implementation is not tail recursive
|
|
471
|
+
type TrimLeft<S extends string> = IfNotAnyOrNever<S, S extends ` ${infer R}` ? TrimLeft<R> : S>;
|
|
472
|
+
|
|
473
|
+
// Hence, instantiations with long strings will fail
|
|
474
|
+
// @ts-expect-error
|
|
475
|
+
type T1 = TrimLeft<NineHundredNinetyNineSpaces>;
|
|
476
|
+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
477
|
+
// Error: Type instantiation is excessively deep and possibly infinite.
|
|
478
|
+
|
|
479
|
+
// To fix this, move the recursion into a helper type
|
|
480
|
+
type TrimLeftOptimised<S extends string> = IfNotAnyOrNever<S, _TrimLeftOptimised<S>>;
|
|
481
|
+
|
|
482
|
+
type _TrimLeftOptimised<S extends string> = S extends ` ${infer R}` ? _TrimLeftOptimised<R> : S;
|
|
483
|
+
|
|
484
|
+
type T2 = TrimLeftOptimised<NineHundredNinetyNineSpaces>;
|
|
485
|
+
//=> ''
|
|
486
|
+
```
|
|
487
|
+
*/
|
|
488
|
+
type IfNotAnyOrNever<T, IfNotAnyOrNever$1, IfAny = any, IfNever = never> = If<IsAny<T>, IfAny, If<IsNever$1<T>, IfNever, IfNotAnyOrNever$1>>;
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-null.d.ts
|
|
491
|
+
/**
|
|
492
|
+
Returns a boolean for whether the given type is `null`.
|
|
493
|
+
|
|
494
|
+
@example
|
|
495
|
+
```
|
|
496
|
+
import type {IsNull} from 'type-fest';
|
|
497
|
+
|
|
498
|
+
type NonNullFallback<T, Fallback> = IsNull<T> extends true ? Fallback : T;
|
|
499
|
+
|
|
500
|
+
type Example1 = NonNullFallback<null, string>;
|
|
501
|
+
//=> string
|
|
502
|
+
|
|
503
|
+
type Example2 = NonNullFallback<number, string>;
|
|
504
|
+
//=? number
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
@category Type Guard
|
|
508
|
+
@category Utilities
|
|
509
|
+
*/
|
|
510
|
+
type IsNull<T> = [T] extends [null] ? true : false;
|
|
511
|
+
//#endregion
|
|
512
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-unknown.d.ts
|
|
513
|
+
/**
|
|
514
|
+
Returns a boolean for whether the given type is `unknown`.
|
|
515
|
+
|
|
516
|
+
@link https://github.com/dsherret/conditional-type-checks/pull/16
|
|
517
|
+
|
|
518
|
+
Useful in type utilities, such as when dealing with unknown data from API calls.
|
|
519
|
+
|
|
520
|
+
@example
|
|
521
|
+
```
|
|
522
|
+
import type {IsUnknown} from 'type-fest';
|
|
523
|
+
|
|
524
|
+
// https://github.com/pajecawav/tiny-global-store/blob/master/src/index.ts
|
|
525
|
+
type Action<TState, TPayload = void> =
|
|
526
|
+
IsUnknown<TPayload> extends true
|
|
527
|
+
? (state: TState) => TState,
|
|
528
|
+
: (state: TState, payload: TPayload) => TState;
|
|
529
|
+
|
|
530
|
+
class Store<TState> {
|
|
531
|
+
constructor(private state: TState) {}
|
|
532
|
+
|
|
533
|
+
execute<TPayload = void>(action: Action<TState, TPayload>, payload?: TPayload): TState {
|
|
534
|
+
this.state = action(this.state, payload);
|
|
535
|
+
return this.state;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// ... other methods
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const store = new Store({value: 1});
|
|
542
|
+
declare const someExternalData: unknown;
|
|
543
|
+
|
|
544
|
+
store.execute(state => ({value: state.value + 1}));
|
|
545
|
+
//=> `TPayload` is `void`
|
|
546
|
+
|
|
547
|
+
store.execute((state, payload) => ({value: state.value + payload}), 5);
|
|
548
|
+
//=> `TPayload` is `5`
|
|
549
|
+
|
|
550
|
+
store.execute((state, payload) => ({value: state.value + payload}), someExternalData);
|
|
551
|
+
//=> Errors: `action` is `(state: TState) => TState`
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
@category Utilities
|
|
555
|
+
*/
|
|
556
|
+
type IsUnknown<T> = (unknown extends T // `T` can be `unknown` or `any`
|
|
557
|
+
? IsNull<T> extends false // `any` can be `null`, but `unknown` can't be
|
|
558
|
+
? true : false : false);
|
|
559
|
+
//#endregion
|
|
560
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/keys.d.ts
|
|
561
|
+
/**
|
|
562
|
+
Disallows any of the given keys.
|
|
563
|
+
*/
|
|
564
|
+
type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/simplify.d.ts
|
|
567
|
+
/**
|
|
568
|
+
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.
|
|
569
|
+
|
|
570
|
+
@example
|
|
571
|
+
```
|
|
572
|
+
import type {Simplify} from 'type-fest';
|
|
573
|
+
|
|
574
|
+
type PositionProps = {
|
|
575
|
+
top: number;
|
|
576
|
+
left: number;
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
type SizeProps = {
|
|
580
|
+
width: number;
|
|
581
|
+
height: number;
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
585
|
+
type Props = Simplify<PositionProps & SizeProps>;
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
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.
|
|
589
|
+
|
|
590
|
+
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`.
|
|
591
|
+
|
|
592
|
+
@example
|
|
593
|
+
```
|
|
594
|
+
import type {Simplify} from 'type-fest';
|
|
595
|
+
|
|
596
|
+
interface SomeInterface {
|
|
597
|
+
foo: number;
|
|
598
|
+
bar?: string;
|
|
599
|
+
baz: number | undefined;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
type SomeType = {
|
|
603
|
+
foo: number;
|
|
604
|
+
bar?: string;
|
|
605
|
+
baz: number | undefined;
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
609
|
+
const someType: SomeType = literal;
|
|
610
|
+
const someInterface: SomeInterface = literal;
|
|
611
|
+
|
|
612
|
+
function fn(object: Record<string, unknown>): void {}
|
|
613
|
+
|
|
614
|
+
fn(literal); // Good: literal object type is sealed
|
|
615
|
+
fn(someType); // Good: type is sealed
|
|
616
|
+
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
617
|
+
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
621
|
+
@see {@link SimplifyDeep}
|
|
622
|
+
@category Object
|
|
623
|
+
*/
|
|
624
|
+
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
625
|
+
//#endregion
|
|
626
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
627
|
+
/**
|
|
628
|
+
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
629
|
+
|
|
630
|
+
This is the counterpart of `PickIndexSignature`.
|
|
631
|
+
|
|
632
|
+
Use-cases:
|
|
633
|
+
- Remove overly permissive signatures from third-party types.
|
|
634
|
+
|
|
635
|
+
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
636
|
+
|
|
637
|
+
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>`.
|
|
638
|
+
|
|
639
|
+
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
640
|
+
|
|
641
|
+
```
|
|
642
|
+
const indexed: Record<string, unknown> = {}; // Allowed
|
|
643
|
+
|
|
644
|
+
const keyed: Record<'foo', unknown> = {}; // Error
|
|
645
|
+
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
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:
|
|
649
|
+
|
|
650
|
+
```
|
|
651
|
+
type Indexed = {} extends Record<string, unknown>
|
|
652
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
653
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
654
|
+
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
655
|
+
|
|
656
|
+
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
657
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
658
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
659
|
+
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
660
|
+
```
|
|
661
|
+
|
|
662
|
+
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`...
|
|
663
|
+
|
|
664
|
+
```
|
|
665
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
666
|
+
|
|
667
|
+
type OmitIndexSignature<ObjectType> = {
|
|
668
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
669
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
670
|
+
};
|
|
671
|
+
```
|
|
672
|
+
|
|
673
|
+
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
674
|
+
|
|
675
|
+
```
|
|
676
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
677
|
+
|
|
678
|
+
type OmitIndexSignature<ObjectType> = {
|
|
679
|
+
[KeyType in keyof ObjectType
|
|
680
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
681
|
+
as {} extends Record<KeyType, unknown>
|
|
682
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
683
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
684
|
+
]: ObjectType[KeyType];
|
|
685
|
+
};
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
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.
|
|
689
|
+
|
|
690
|
+
@example
|
|
691
|
+
```
|
|
692
|
+
import type {OmitIndexSignature} from 'type-fest';
|
|
693
|
+
|
|
694
|
+
interface Example {
|
|
695
|
+
// These index signatures will be removed.
|
|
696
|
+
[x: string]: any
|
|
697
|
+
[x: number]: any
|
|
698
|
+
[x: symbol]: any
|
|
699
|
+
[x: `head-${string}`]: string
|
|
700
|
+
[x: `${string}-tail`]: string
|
|
701
|
+
[x: `head-${string}-tail`]: string
|
|
702
|
+
[x: `${bigint}`]: string
|
|
703
|
+
[x: `embedded-${number}`]: string
|
|
704
|
+
|
|
705
|
+
// These explicitly defined keys will remain.
|
|
706
|
+
foo: 'bar';
|
|
707
|
+
qux?: 'baz';
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
711
|
+
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
712
|
+
```
|
|
713
|
+
|
|
714
|
+
@see {@link PickIndexSignature}
|
|
715
|
+
@category Object
|
|
716
|
+
*/
|
|
717
|
+
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
720
|
+
/**
|
|
721
|
+
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
722
|
+
|
|
723
|
+
This is the counterpart of `OmitIndexSignature`.
|
|
724
|
+
|
|
725
|
+
@example
|
|
726
|
+
```
|
|
727
|
+
import type {PickIndexSignature} from 'type-fest';
|
|
728
|
+
|
|
729
|
+
declare const symbolKey: unique symbol;
|
|
730
|
+
|
|
731
|
+
type Example = {
|
|
732
|
+
// These index signatures will remain.
|
|
733
|
+
[x: string]: unknown;
|
|
734
|
+
[x: number]: unknown;
|
|
735
|
+
[x: symbol]: unknown;
|
|
736
|
+
[x: `head-${string}`]: string;
|
|
737
|
+
[x: `${string}-tail`]: string;
|
|
738
|
+
[x: `head-${string}-tail`]: string;
|
|
739
|
+
[x: `${bigint}`]: string;
|
|
740
|
+
[x: `embedded-${number}`]: string;
|
|
741
|
+
|
|
742
|
+
// These explicitly defined keys will be removed.
|
|
743
|
+
['kebab-case-key']: string;
|
|
744
|
+
[symbolKey]: string;
|
|
745
|
+
foo: 'bar';
|
|
746
|
+
qux?: 'baz';
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
750
|
+
// {
|
|
751
|
+
// [x: string]: unknown;
|
|
752
|
+
// [x: number]: unknown;
|
|
753
|
+
// [x: symbol]: unknown;
|
|
754
|
+
// [x: `head-${string}`]: string;
|
|
755
|
+
// [x: `${string}-tail`]: string;
|
|
756
|
+
// [x: `head-${string}-tail`]: string;
|
|
757
|
+
// [x: `${bigint}`]: string;
|
|
758
|
+
// [x: `embedded-${number}`]: string;
|
|
759
|
+
// }
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
@see {@link OmitIndexSignature}
|
|
763
|
+
@category Object
|
|
764
|
+
*/
|
|
765
|
+
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
766
|
+
//#endregion
|
|
767
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/merge.d.ts
|
|
768
|
+
// Merges two objects without worrying about index signatures.
|
|
769
|
+
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
773
|
+
|
|
774
|
+
@example
|
|
775
|
+
```
|
|
776
|
+
import type {Merge} from 'type-fest';
|
|
777
|
+
|
|
778
|
+
interface Foo {
|
|
779
|
+
[x: string]: unknown;
|
|
780
|
+
[x: number]: unknown;
|
|
781
|
+
foo: string;
|
|
782
|
+
bar: symbol;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
type Bar = {
|
|
786
|
+
[x: number]: number;
|
|
787
|
+
[x: symbol]: unknown;
|
|
788
|
+
bar: Date;
|
|
789
|
+
baz: boolean;
|
|
790
|
+
};
|
|
791
|
+
|
|
792
|
+
export type FooBar = Merge<Foo, Bar>;
|
|
793
|
+
// => {
|
|
794
|
+
// [x: string]: unknown;
|
|
795
|
+
// [x: number]: number;
|
|
796
|
+
// [x: symbol]: unknown;
|
|
797
|
+
// foo: string;
|
|
798
|
+
// bar: Date;
|
|
799
|
+
// baz: boolean;
|
|
800
|
+
// }
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
@category Object
|
|
804
|
+
*/
|
|
805
|
+
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/internal/object.d.ts
|
|
808
|
+
/**
|
|
809
|
+
Merges user specified options with default options.
|
|
810
|
+
|
|
811
|
+
@example
|
|
812
|
+
```
|
|
813
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
814
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
815
|
+
type SpecifiedOptions = {leavesOnly: true};
|
|
816
|
+
|
|
817
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
818
|
+
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
@example
|
|
822
|
+
```
|
|
823
|
+
// Complains if default values are not provided for optional options
|
|
824
|
+
|
|
825
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
826
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
827
|
+
type SpecifiedOptions = {};
|
|
828
|
+
|
|
829
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
830
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
831
|
+
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
832
|
+
```
|
|
833
|
+
|
|
834
|
+
@example
|
|
835
|
+
```
|
|
836
|
+
// Complains if an option's default type does not conform to the expected type
|
|
837
|
+
|
|
838
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
839
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
840
|
+
type SpecifiedOptions = {};
|
|
841
|
+
|
|
842
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
843
|
+
// ~~~~~~~~~~~~~~~~~~~
|
|
844
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
845
|
+
```
|
|
846
|
+
|
|
847
|
+
@example
|
|
848
|
+
```
|
|
849
|
+
// Complains if an option's specified type does not conform to the expected type
|
|
850
|
+
|
|
851
|
+
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
852
|
+
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
853
|
+
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
854
|
+
|
|
855
|
+
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
856
|
+
// ~~~~~~~~~~~~~~~~
|
|
857
|
+
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
858
|
+
```
|
|
859
|
+
*/
|
|
860
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever$1<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
861
|
+
//#endregion
|
|
862
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/or.d.ts
|
|
863
|
+
/**
|
|
864
|
+
Returns a boolean for whether either of two given types is true.
|
|
865
|
+
|
|
866
|
+
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
|
|
867
|
+
|
|
868
|
+
@example
|
|
869
|
+
```
|
|
870
|
+
import type {Or} from 'type-fest';
|
|
871
|
+
|
|
872
|
+
type TT = Or<true, true>;
|
|
873
|
+
//=> true
|
|
874
|
+
|
|
875
|
+
type TF = Or<true, false>;
|
|
876
|
+
//=> true
|
|
877
|
+
|
|
878
|
+
type FT = Or<false, true>;
|
|
879
|
+
//=> true
|
|
880
|
+
|
|
881
|
+
type FF = Or<false, false>;
|
|
882
|
+
//=> false
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
886
|
+
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
887
|
+
|
|
888
|
+
@example
|
|
889
|
+
```
|
|
890
|
+
import type {Or} from 'type-fest';
|
|
891
|
+
|
|
892
|
+
type A = Or<false, boolean>;
|
|
893
|
+
//=> boolean
|
|
894
|
+
|
|
895
|
+
type B = Or<boolean, false>;
|
|
896
|
+
//=> boolean
|
|
897
|
+
|
|
898
|
+
type C = Or<true, boolean>;
|
|
899
|
+
//=> true
|
|
900
|
+
|
|
901
|
+
type D = Or<boolean, true>;
|
|
902
|
+
//=> true
|
|
903
|
+
|
|
904
|
+
type E = Or<boolean, boolean>;
|
|
905
|
+
//=> boolean
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
909
|
+
|
|
910
|
+
@example
|
|
911
|
+
```
|
|
912
|
+
import type {Or} from 'type-fest';
|
|
913
|
+
|
|
914
|
+
type A = Or<true, never>;
|
|
915
|
+
//=> true
|
|
916
|
+
|
|
917
|
+
type B = Or<never, true>;
|
|
918
|
+
//=> true
|
|
919
|
+
|
|
920
|
+
type C = Or<false, never>;
|
|
921
|
+
//=> false
|
|
922
|
+
|
|
923
|
+
type D = Or<never, false>;
|
|
924
|
+
//=> false
|
|
925
|
+
|
|
926
|
+
type E = Or<boolean, never>;
|
|
927
|
+
//=> boolean
|
|
928
|
+
|
|
929
|
+
type F = Or<never, boolean>;
|
|
930
|
+
//=> boolean
|
|
931
|
+
|
|
932
|
+
type G = Or<never, never>;
|
|
933
|
+
//=> false
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
@see {@link And}
|
|
937
|
+
@see {@link Xor}
|
|
938
|
+
*/
|
|
939
|
+
type Or<A$1 extends boolean, B$1 extends boolean> = _Or<If<IsNever$1<A$1>, false, A$1>, If<IsNever$1<B$1>, false, B$1>>;
|
|
940
|
+
// `never` is treated as `false`
|
|
941
|
+
|
|
942
|
+
type _Or<A$1 extends boolean, B$1 extends boolean> = A$1 extends true ? true : B$1 extends true ? true : false;
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/require-exactly-one.d.ts
|
|
945
|
+
/**
|
|
946
|
+
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
|
|
947
|
+
|
|
948
|
+
Use-cases:
|
|
949
|
+
- Creating interfaces for components that only need one of the keys to display properly.
|
|
950
|
+
- Declaring generic keys in a single place for a single use-case that gets narrowed down via `RequireExactlyOne`.
|
|
951
|
+
|
|
952
|
+
The caveat with `RequireExactlyOne` is that TypeScript doesn't always know at compile time every key that will exist at runtime. Therefore `RequireExactlyOne` can't do anything to prevent extra keys it doesn't know about.
|
|
953
|
+
|
|
954
|
+
@example
|
|
955
|
+
```
|
|
956
|
+
import type {RequireExactlyOne} from 'type-fest';
|
|
957
|
+
|
|
958
|
+
type Responder = {
|
|
959
|
+
text: () => string;
|
|
960
|
+
json: () => string;
|
|
961
|
+
secure: boolean;
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
|
|
965
|
+
// Adding a `text` key here would cause a compile error.
|
|
966
|
+
|
|
967
|
+
json: () => '{"message": "ok"}',
|
|
968
|
+
secure: true
|
|
969
|
+
};
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
@category Object
|
|
973
|
+
*/
|
|
974
|
+
type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever$1<KeysType>, never, _RequireExactlyOne<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
975
|
+
type _RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType> = { [Key in KeysType]: (Required<Pick<ObjectType, Key>> & Partial<Record<Exclude<KeysType, Key>, never>>) }[KeysType] & Omit<ObjectType, KeysType>;
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/require-one-or-none.d.ts
|
|
978
|
+
/**
|
|
979
|
+
Create a type that requires exactly one of the given keys and disallows more, or none of the given keys. The remaining keys are kept as is.
|
|
980
|
+
|
|
981
|
+
@example
|
|
982
|
+
```
|
|
983
|
+
import type {RequireOneOrNone} from 'type-fest';
|
|
984
|
+
|
|
985
|
+
type Responder = RequireOneOrNone<{
|
|
986
|
+
text: () => string;
|
|
987
|
+
json: () => string;
|
|
988
|
+
secure: boolean;
|
|
989
|
+
}, 'text' | 'json'>;
|
|
990
|
+
|
|
991
|
+
const responder1: Responder = {
|
|
992
|
+
secure: true
|
|
993
|
+
};
|
|
994
|
+
|
|
995
|
+
const responder2: Responder = {
|
|
996
|
+
text: () => '{"message": "hi"}',
|
|
997
|
+
secure: true
|
|
998
|
+
};
|
|
999
|
+
|
|
1000
|
+
const responder3: Responder = {
|
|
1001
|
+
json: () => '{"message": "ok"}',
|
|
1002
|
+
secure: true
|
|
1003
|
+
};
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
@category Object
|
|
1007
|
+
*/
|
|
1008
|
+
type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, If<IsNever$1<KeysType>, ObjectType, _RequireOneOrNone<ObjectType, If<IsAny<KeysType>, keyof ObjectType, KeysType>>>>;
|
|
1009
|
+
type _RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType> = (RequireExactlyOne<ObjectType, KeysType> | RequireNone<KeysType>) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/is-union.d.ts
|
|
1012
|
+
/**
|
|
1013
|
+
Returns a boolean for whether the given type is a union.
|
|
1014
|
+
|
|
1015
|
+
@example
|
|
1016
|
+
```
|
|
1017
|
+
import type {IsUnion} from 'type-fest';
|
|
1018
|
+
|
|
1019
|
+
type A = IsUnion<string | number>;
|
|
1020
|
+
//=> true
|
|
1021
|
+
|
|
1022
|
+
type B = IsUnion<string>;
|
|
1023
|
+
//=> false
|
|
1024
|
+
```
|
|
1025
|
+
*/
|
|
1026
|
+
type IsUnion$1<T> = InternalIsUnion<T>;
|
|
1027
|
+
/**
|
|
1028
|
+
The actual implementation of `IsUnion`.
|
|
1029
|
+
*/
|
|
1030
|
+
type InternalIsUnion<T, U$1 = T> = (IsNever$1<T> extends true ? false : T extends any ? [U$1] extends [T] ? false : true : never) extends infer Result
|
|
1031
|
+
// In some cases `Result` will return `false | true` which is `boolean`,
|
|
1032
|
+
// that means `T` has at least two types and it's a union type,
|
|
1033
|
+
// so we will return `true` instead of `boolean`.
|
|
1034
|
+
? boolean extends Result ? true : Result : never; // Should never happen
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/partial-deep.d.ts
|
|
1037
|
+
/**
|
|
1038
|
+
@see {@link PartialDeep}
|
|
1039
|
+
*/
|
|
1040
|
+
type PartialDeepOptions = {
|
|
1041
|
+
/**
|
|
1042
|
+
Whether to affect the individual elements of arrays and tuples.
|
|
1043
|
+
@default false
|
|
1044
|
+
*/
|
|
1045
|
+
readonly recurseIntoArrays?: boolean;
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
Allows `undefined` values in non-tuple arrays.
|
|
1049
|
+
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
1050
|
+
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
1051
|
+
@default false
|
|
1052
|
+
@example
|
|
1053
|
+
You can allow `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}` as the second type argument:
|
|
1054
|
+
```
|
|
1055
|
+
import type {PartialDeep} from 'type-fest';
|
|
1056
|
+
type Settings = {
|
|
1057
|
+
languages: string[];
|
|
1058
|
+
};
|
|
1059
|
+
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: true}>;
|
|
1060
|
+
partialSettings.languages = [undefined]; // OK
|
|
1061
|
+
```
|
|
1062
|
+
*/
|
|
1063
|
+
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
1064
|
+
};
|
|
1065
|
+
type DefaultPartialDeepOptions = {
|
|
1066
|
+
recurseIntoArrays: false;
|
|
1067
|
+
allowUndefinedInNonTupleArrays: false;
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
Create a type from another type with all keys and nested keys set to optional.
|
|
1072
|
+
|
|
1073
|
+
Use-cases:
|
|
1074
|
+
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
1075
|
+
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
1076
|
+
|
|
1077
|
+
@example
|
|
1078
|
+
```
|
|
1079
|
+
import type {PartialDeep} from 'type-fest';
|
|
1080
|
+
|
|
1081
|
+
let settings = {
|
|
1082
|
+
textEditor: {
|
|
1083
|
+
fontSize: 14,
|
|
1084
|
+
fontColor: '#000000',
|
|
1085
|
+
fontWeight: 400,
|
|
1086
|
+
},
|
|
1087
|
+
autocomplete: false,
|
|
1088
|
+
autosave: true,
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
const applySavedSettings = (savedSettings: PartialDeep<typeof settings>) => (
|
|
1092
|
+
{...settings, ...savedSettings, textEditor: {...settings.textEditor, ...savedSettings.textEditor}}
|
|
1093
|
+
);
|
|
1094
|
+
|
|
1095
|
+
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
1096
|
+
```
|
|
1097
|
+
|
|
1098
|
+
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
1099
|
+
|
|
1100
|
+
```
|
|
1101
|
+
import type {PartialDeep} from 'type-fest';
|
|
1102
|
+
|
|
1103
|
+
type Shape = {
|
|
1104
|
+
dimensions: [number, number];
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
const partialShape: PartialDeep<Shape, {recurseIntoArrays: true}> = {
|
|
1108
|
+
dimensions: [], // OK
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
partialShape.dimensions = [15]; // OK
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
@see {@link PartialDeepOptions}
|
|
1115
|
+
|
|
1116
|
+
@category Object
|
|
1117
|
+
@category Array
|
|
1118
|
+
@category Set
|
|
1119
|
+
@category Map
|
|
1120
|
+
*/
|
|
1121
|
+
type PartialDeep<T, Options extends PartialDeepOptions = {}> = _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
1122
|
+
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown)) ? T : T extends Map<infer KeyType, infer ValueType> ? PartialMapDeep<KeyType, ValueType, Options> : T extends Set<infer ItemType> ? PartialSetDeep<ItemType, Options> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? PartialReadonlyMapDeep<KeyType, ValueType, Options> : T extends ReadonlySet<infer ItemType> ? PartialReadonlySetDeep<ItemType, Options> : T extends ((...arguments_: any[]) => unknown) ? IsNever$1<keyof T> extends true ? T // For functions with no properties
|
|
1123
|
+
: HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & PartialObjectDeep<T, Options> : T extends object ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
1124
|
+
? Options['recurseIntoArrays'] extends true ? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
1125
|
+
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
1126
|
+
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>> : PartialObjectDeep<T, Options> // Tuples behave properly
|
|
1127
|
+
: T // If they don't opt into array testing, just use the original type
|
|
1128
|
+
: PartialObjectDeep<T, Options> : unknown;
|
|
1129
|
+
|
|
1130
|
+
/**
|
|
1131
|
+
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
1132
|
+
*/
|
|
1133
|
+
type PartialMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
1137
|
+
*/
|
|
1138
|
+
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
1142
|
+
*/
|
|
1143
|
+
type PartialReadonlyMapDeep<KeyType$1, ValueType$1, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType$1, Options>, _PartialDeep<ValueType$1, Options>>;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
1147
|
+
*/
|
|
1148
|
+
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
1152
|
+
*/
|
|
1153
|
+
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = { [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options> };
|
|
1154
|
+
//#endregion
|
|
1155
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/required-deep.d.ts
|
|
1156
|
+
/**
|
|
1157
|
+
Create a type from another type with all keys and nested keys set to required.
|
|
1158
|
+
|
|
1159
|
+
Use-cases:
|
|
1160
|
+
- Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
|
|
1161
|
+
- Modeling the resulting type after a deep merge with a set of defaults.
|
|
1162
|
+
|
|
1163
|
+
@example
|
|
1164
|
+
```
|
|
1165
|
+
import type {RequiredDeep} from 'type-fest';
|
|
1166
|
+
|
|
1167
|
+
type Settings = {
|
|
1168
|
+
textEditor?: {
|
|
1169
|
+
fontSize?: number;
|
|
1170
|
+
fontColor?: string;
|
|
1171
|
+
fontWeight?: number | undefined;
|
|
1172
|
+
};
|
|
1173
|
+
autocomplete?: boolean;
|
|
1174
|
+
autosave?: boolean | undefined;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
type RequiredSettings = RequiredDeep<Settings>;
|
|
1178
|
+
//=> {
|
|
1179
|
+
// textEditor: {
|
|
1180
|
+
// fontSize: number;
|
|
1181
|
+
// fontColor: string;
|
|
1182
|
+
// fontWeight: number | undefined;
|
|
1183
|
+
// };
|
|
1184
|
+
// autocomplete: boolean;
|
|
1185
|
+
// autosave: boolean | undefined;
|
|
1186
|
+
// }
|
|
1187
|
+
```
|
|
1188
|
+
|
|
1189
|
+
Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
1190
|
+
|
|
1191
|
+
@category Utilities
|
|
1192
|
+
@category Object
|
|
1193
|
+
@category Array
|
|
1194
|
+
@category Set
|
|
1195
|
+
@category Map
|
|
1196
|
+
*/
|
|
1197
|
+
type RequiredDeep<T> = T extends BuiltIns ? T : T extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : T extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : T extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : T extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : T extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : T extends ((...arguments_: any[]) => unknown) ? IsNever$1<keyof T> extends true ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments_: Parameters<T>) => ReturnType<T>) & RequiredObjectDeep<T> : T extends object ? RequiredObjectDeep<T> : unknown;
|
|
1198
|
+
type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region ../../node_modules/.pnpm/type-fest@5.2.0/node_modules/type-fest/source/union-to-tuple.d.ts
|
|
1201
|
+
/**
|
|
1202
|
+
Returns the last element of a union type.
|
|
1203
|
+
|
|
1204
|
+
@example
|
|
1205
|
+
```
|
|
1206
|
+
type Last = LastOfUnion<1 | 2 | 3>;
|
|
1207
|
+
//=> 3
|
|
1208
|
+
```
|
|
1209
|
+
*/
|
|
1210
|
+
type LastOfUnion<T> = UnionToIntersection<T extends any ? () => T : never> extends (() => (infer R)) ? R : never;
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
1214
|
+
|
|
1215
|
+
"Unordered" means the elements of the tuple are not guaranteed to be in the same order as in the union type. The arrangement can appear random and may change at any time.
|
|
1216
|
+
|
|
1217
|
+
This can be useful when you have objects with a finite set of keys and want a type defining only the allowed keys, but do not want to repeat yourself.
|
|
1218
|
+
|
|
1219
|
+
@example
|
|
1220
|
+
```
|
|
1221
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1222
|
+
|
|
1223
|
+
type Numbers = 1 | 2 | 3;
|
|
1224
|
+
type NumbersTuple = UnionToTuple<Numbers>;
|
|
1225
|
+
//=> [1, 2, 3]
|
|
1226
|
+
```
|
|
1227
|
+
|
|
1228
|
+
@example
|
|
1229
|
+
```
|
|
1230
|
+
import type {UnionToTuple} from 'type-fest';
|
|
1231
|
+
|
|
1232
|
+
const pets = {
|
|
1233
|
+
dog: '🐶',
|
|
1234
|
+
cat: '🐱',
|
|
1235
|
+
snake: '🐍',
|
|
1236
|
+
};
|
|
1237
|
+
|
|
1238
|
+
type Pet = keyof typeof pets;
|
|
1239
|
+
//=> 'dog' | 'cat' | 'snake'
|
|
1240
|
+
|
|
1241
|
+
const petList = Object.keys(pets) as UnionToTuple<Pet>;
|
|
1242
|
+
//=> ['dog', 'cat', 'snake']
|
|
1243
|
+
```
|
|
1244
|
+
|
|
1245
|
+
@category Array
|
|
1246
|
+
*/
|
|
1247
|
+
type UnionToTuple<T, L = LastOfUnion<T>> = IsNever$1<T> extends false ? [...UnionToTuple<Exclude<T, L>>, L] : [];
|
|
1248
|
+
//#endregion
|
|
31
1249
|
//#region src/types/core/modifiers.types.d.ts
|
|
32
1250
|
interface RegleBehaviourOptions {
|
|
33
1251
|
/**
|
|
@@ -250,6 +1468,44 @@ type SafeProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | unde
|
|
|
250
1468
|
type IsPropertyOutputRequired<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? unknown : NonNullable<TState$1> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState$1>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState$1> extends Record<string, any> ? NonNullable<TState$1> : {}, TRule> extends false ? false : true : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends false ? false : true : false : false;
|
|
251
1469
|
type SafeFieldProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState$1> : MaybeOutput<TState$1>;
|
|
252
1470
|
//#endregion
|
|
1471
|
+
//#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/utils.d.ts
|
|
1472
|
+
/**
|
|
1473
|
+
* Negates a boolean type.
|
|
1474
|
+
*/
|
|
1475
|
+
type Not<T extends boolean> = T extends true ? false : true;
|
|
1476
|
+
/**
|
|
1477
|
+
* Checks if the given type is `never`.
|
|
1478
|
+
*/
|
|
1479
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
1480
|
+
/**
|
|
1481
|
+
* Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
|
|
1482
|
+
* 1. If either type is `never`, the result is `true` iff the other type is also `never`.
|
|
1483
|
+
* 2. Types are wrapped in a 1-tuple so that union types are not distributed - instead we consider `string | number` to _not_ extend `number`. If we used `Left extends Right` directly you would get `Extends<string | number, number>` => `false | true` => `boolean`.
|
|
1484
|
+
*/
|
|
1485
|
+
type Extends<Left, Right> = IsNever<Left> extends true ? IsNever<Right> : [Left] extends [Right] ? true : false;
|
|
1486
|
+
/**
|
|
1487
|
+
* Convert a union to an intersection.
|
|
1488
|
+
* `A | B | C` -\> `A & B & C`
|
|
1489
|
+
*/
|
|
1490
|
+
type UnionToIntersection$1<Union> = (Union extends any ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection : never;
|
|
1491
|
+
/**
|
|
1492
|
+
* Get the last element of a union.
|
|
1493
|
+
* First, converts to a union of `() => T` functions,
|
|
1494
|
+
* then uses {@linkcode UnionToIntersection} to get the last one.
|
|
1495
|
+
*/
|
|
1496
|
+
type LastOf<Union> = UnionToIntersection$1<Union extends any ? () => Union : never> extends (() => infer R) ? R : never;
|
|
1497
|
+
/**
|
|
1498
|
+
* Intermediate type for {@linkcode UnionToTuple} which pushes the
|
|
1499
|
+
* "last" union member to the end of a tuple, and recursively prepends
|
|
1500
|
+
* the remainder of the union.
|
|
1501
|
+
*/
|
|
1502
|
+
type TuplifyUnion<Union, LastElement = LastOf<Union>> = IsNever<Union> extends true ? [] : [...TuplifyUnion<Exclude<Union, LastElement>>, LastElement];
|
|
1503
|
+
/**
|
|
1504
|
+
* Convert a union like `1 | 2 | 3` to a tuple like `[1, 2, 3]`.
|
|
1505
|
+
*/
|
|
1506
|
+
type UnionToTuple$1<Union> = TuplifyUnion<Union>;
|
|
1507
|
+
type IsUnion<T> = Not<Extends<UnionToTuple$1<T>['length'], 1>>;
|
|
1508
|
+
//#endregion
|
|
253
1509
|
//#region src/types/core/variants.types.d.ts
|
|
254
1510
|
type NarrowVariant<TRoot extends {
|
|
255
1511
|
[x: string]: unknown;
|
|
@@ -261,7 +1517,7 @@ type NarrowVariant<TRoot extends {
|
|
|
261
1517
|
} ? V : unknown)> = Extract<TRoot, { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> }> & {
|
|
262
1518
|
$fields: Extract<TRoot['$fields'], { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> }>;
|
|
263
1519
|
};
|
|
264
|
-
type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion
|
|
1520
|
+
type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState$1>> extends true ? Omit<RegleStatus<TState$1, TRules$1, TShortcuts>, '$fields'> & {
|
|
265
1521
|
$fields: ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>];
|
|
266
1522
|
} & (HasNamedKeys<TState$1> extends true ? ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>] : {}) : RegleStatus<TState$1, TRules$1, TShortcuts>;
|
|
267
1523
|
type ProcessChildrenFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState$1>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } : {} };
|
|
@@ -470,11 +1726,11 @@ type EnumLike = {
|
|
|
470
1726
|
type enumType<T extends Record<string, unknown>> = T[keyof T];
|
|
471
1727
|
type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
|
|
472
1728
|
type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
|
|
473
|
-
type HasNamedKeys<T> = IsUnion
|
|
1729
|
+
type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
|
|
474
1730
|
type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
|
|
475
1731
|
//#endregion
|
|
476
1732
|
//#region src/types/utils/infer.types.d.ts
|
|
477
|
-
type InferInput<TRules$1 extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TMarkMaybe extends boolean = true> = TRules$1 extends MaybeRef<StandardSchemaV1<infer State>> ? State : IsUnion<UnwrapSimple<TRules$1>> extends true ? InferTupleUnionInput<UnionToTuple<UnwrapSimple<TRules$1>>>[number] : TMarkMaybe extends true ? Prettify<{ [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? K : never]?: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> } & { [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? never : K]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }> : Prettify<{ [K in keyof UnwrapSimple<TRules$1>]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }>;
|
|
1733
|
+
type InferInput<TRules$1 extends MaybeRef<ReglePartialRuleTree<Record<string, any>, any>> | ((state: any) => ReglePartialRuleTree<Record<string, any>, any>) | MaybeRef<StandardSchemaV1<any>>, TMarkMaybe extends boolean = true> = TRules$1 extends MaybeRef<StandardSchemaV1<infer State>> ? State : IsUnion$1<UnwrapSimple<TRules$1>> extends true ? InferTupleUnionInput<UnionToTuple<UnwrapSimple<TRules$1>>>[number] : TMarkMaybe extends true ? Prettify<{ [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? K : never]?: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> } & { [K in keyof UnwrapSimple<TRules$1> as UnwrapSimple<TRules$1>[K] extends MaybeRef<RegleRuleDecl<any, any>> ? never : K]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }> : Prettify<{ [K in keyof UnwrapSimple<TRules$1>]: ProcessInputChildren<UnwrapSimple<TRules$1>[K], TMarkMaybe> }>;
|
|
478
1734
|
type ProcessInputChildren<TRule extends unknown, TMarkMaybe extends boolean> = TRule extends {
|
|
479
1735
|
$each: RegleCollectionEachRules<any, any>;
|
|
480
1736
|
} ? ExtractFromGetter<TRule['$each']> extends ReglePartialRuleTree<any, any> ? InferInput<ExtractFromGetter<TRule['$each']>, TMarkMaybe>[] : any[] : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? [ExtractTypeFromRules<UnwrapRef<TRule>>] extends [never] ? unknown : ExtractTypeFromRules<UnwrapRef<TRule>> : TRule extends ReglePartialRuleTree<any, any> ? InferInput<TRule, TMarkMaybe> : string;
|
|
@@ -482,7 +1738,7 @@ type ExtractTypeFromRules<TRules$1 extends RegleRuleDecl<any, any>> = FilterRule
|
|
|
482
1738
|
type: infer Input;
|
|
483
1739
|
} ? Input : [FilterRulesWithSingleType<TRules$1>[keyof FilterRulesWithSingleType<TRules$1>]] extends [never] ? FilterRulesWithInput<TRules$1>[keyof FilterRulesWithInput<TRules$1>] : FilterRulesWithSingleType<TRules$1>[keyof FilterRulesWithSingleType<TRules$1>];
|
|
484
1740
|
type FilterRulesWithInput<TRules$1 extends RegleRuleDecl<any, any>> = { [K in keyof TRules$1 as TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : K : never]: TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? Input : unknown };
|
|
485
|
-
type FilterRulesWithSingleType<TRules$1 extends RegleRuleDecl<any, any>> = { [K in keyof TRules$1 as TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion<NonNullable<Input>> extends true ? never : K : never]: TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? IsUnion<NonNullable<Input>> extends true ? unknown : Input : unknown };
|
|
1741
|
+
type FilterRulesWithSingleType<TRules$1 extends RegleRuleDecl<any, any>> = { [K in keyof TRules$1 as TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? unknown extends Input ? never : IsUnion$1<NonNullable<Input>> extends true ? never : K : never]: TRules$1[K] extends RegleRuleDefinition<any, any, any, any, infer Input> ? IsUnion$1<NonNullable<Input>> extends true ? unknown : Input : unknown };
|
|
486
1742
|
type InferTupleUnionInput<T extends any[]> = T extends [infer F extends ReglePartialRuleTree, ...infer R] ? [InferInput<F, true>, ...InferTupleUnionInput<R>] : [];
|
|
487
1743
|
//#endregion
|
|
488
1744
|
//#region src/types/rules/rule.params.types.d.ts
|
|
@@ -788,7 +2044,7 @@ type RegleRoot<TState$1 extends Record<string, unknown> = {}, TRules$1 extends R
|
|
|
788
2044
|
*/
|
|
789
2045
|
$groups: { readonly [TKey in keyof TValidationGroups]: RegleValidationGroupOutput };
|
|
790
2046
|
});
|
|
791
|
-
type ProcessNestedFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}, TIsFields extends boolean = false> = Or<HasNamedKeys<TState$1>, TIsFields> extends true ? { readonly [TKey in keyof TState$1 as TRules$1[TKey] extends NonNullable<TRules$1[TKey]> ? NonNullable<TRules$1[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules$1[TKey]> extends true ? TKey : never : never : TKey]: IsUnion
|
|
2047
|
+
type ProcessNestedFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}, TIsFields extends boolean = false> = Or<HasNamedKeys<TState$1>, TIsFields> extends true ? { readonly [TKey in keyof TState$1 as TRules$1[TKey] extends NonNullable<TRules$1[TKey]> ? NonNullable<TRules$1[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules$1[TKey]> extends true ? TKey : never : never : TKey]: IsUnion<NonNullable<TRules$1[TKey]>> extends true ? ExtendOnlyRealRecord<TState$1[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState$1>[TKey], NonNullable<TRules$1[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> } & { readonly [TKey in keyof TState$1 as TRules$1[TKey] extends NonNullable<TRules$1[TKey]> ? NonNullable<TRules$1[TKey]> extends MaybeRef<RegleRuleDecl> ? IsEmptyObject<TRules$1[TKey]> extends true ? never : TKey : TKey : never]-?: IsUnion<NonNullable<TRules$1[TKey]>> extends true ? ExtendOnlyRealRecord<TState$1[TKey]> extends true ? MaybeVariantStatus<NonNullable<TState$1>[TKey], NonNullable<TRules$1[TKey]>, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> : InferRegleStatusType<NonNullable<TRules$1[TKey]>, NonNullable<TState$1>, TKey, TShortcuts> } : {};
|
|
792
2048
|
/**
|
|
793
2049
|
* @public
|
|
794
2050
|
*/
|