@react-querybuilder/core 8.9.2 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{arrayUtils-BF1P8iHS.mjs → arrayUtils-C9sO4qLO.mjs} +3 -75
- package/dist/arrayUtils-C9sO4qLO.mjs.map +1 -0
- package/dist/arrayUtils-QxZOZTf6.js +73 -0
- package/dist/arrayUtils-QxZOZTf6.js.map +1 -0
- package/dist/basic-BmpEwexQ.d.mts +363 -0
- package/dist/basic-CDDA-KZa.d.ts +363 -0
- package/dist/cjs/react-querybuilder_core.cjs.development.d.ts +553 -1247
- package/dist/cjs/react-querybuilder_core.cjs.development.js +408 -121
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +553 -1247
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/{convertQuery-H7RhQiIc.mjs → convertQuery-BUgyz1GA.mjs} +2 -2
- package/dist/{convertQuery-H7RhQiIc.mjs.map → convertQuery-BUgyz1GA.mjs.map} +1 -1
- package/dist/{export-r-V7bU31.d.mts → export-Ccjfea21.d.mts} +3 -2
- package/dist/{export-DyrnTh6K.d.ts → export-GUuxJ7zR.d.ts} +3 -2
- package/dist/formatQuery.d.mts +3 -2
- package/dist/formatQuery.d.ts +3 -2
- package/dist/formatQuery.js +217 -87
- package/dist/formatQuery.js.map +1 -1
- package/dist/formatQuery.mjs +217 -87
- package/dist/formatQuery.mjs.map +1 -1
- package/dist/{import-Cksobmln.d.ts → import-D-hm1phN.d.ts} +2 -2
- package/dist/{import-BwbbP4oU.d.mts → import-Dxevzw_-.d.mts} +2 -2
- package/dist/{isRuleGroup-CnhYpLOM.mjs → isRuleGroup-CGe_rb2w.mjs} +1 -1
- package/dist/{isRuleGroup-CnhYpLOM.mjs.map → isRuleGroup-CGe_rb2w.mjs.map} +1 -1
- package/dist/{optGroupUtils-CXLgyg2i.js → optGroupUtils-B0hTpodo.js} +114 -1
- package/dist/optGroupUtils-B0hTpodo.js.map +1 -0
- package/dist/{optGroupUtils-Duv-M8rf.mjs → optGroupUtils-DrubUpx0.mjs} +86 -3
- package/dist/optGroupUtils-DrubUpx0.mjs.map +1 -0
- package/dist/parseCEL.d.mts +292 -11
- package/dist/parseCEL.d.ts +292 -11
- package/dist/parseCEL.js +114 -30
- package/dist/parseCEL.js.map +1 -1
- package/dist/parseCEL.mjs +69 -31
- package/dist/parseCEL.mjs.map +1 -1
- package/dist/parseJSONata.d.mts +3 -2
- package/dist/parseJSONata.d.ts +3 -2
- package/dist/parseJSONata.js +49 -77
- package/dist/parseJSONata.js.map +1 -1
- package/dist/parseJSONata.mjs +4 -5
- package/dist/parseJSONata.mjs.map +1 -1
- package/dist/parseJsonLogic.d.mts +4 -3
- package/dist/parseJsonLogic.d.ts +4 -3
- package/dist/parseJsonLogic.js +5 -6
- package/dist/parseJsonLogic.js.map +1 -1
- package/dist/parseJsonLogic.mjs +5 -6
- package/dist/parseJsonLogic.mjs.map +1 -1
- package/dist/parseMongoDB.d.mts +3 -2
- package/dist/parseMongoDB.d.ts +3 -2
- package/dist/parseMongoDB.js +15 -16
- package/dist/parseMongoDB.js.map +1 -1
- package/dist/parseMongoDB.mjs +5 -6
- package/dist/parseMongoDB.mjs.map +1 -1
- package/dist/{parseNumber-BtGKa58z.mjs → parseNumber-B_-sR6d5.mjs} +1 -1
- package/dist/{parseNumber-BtGKa58z.mjs.map → parseNumber-B_-sR6d5.mjs.map} +1 -1
- package/dist/{parseNumber-Bcys1kOH.js → parseNumber-D4iQDxK-.js} +1 -1
- package/dist/{parseNumber-Bcys1kOH.js.map → parseNumber-D4iQDxK-.js.map} +1 -1
- package/dist/parseSQL.d.mts +3 -2
- package/dist/parseSQL.d.ts +3 -2
- package/dist/parseSQL.js +11 -15
- package/dist/parseSQL.js.map +1 -1
- package/dist/parseSQL.mjs +12 -16
- package/dist/parseSQL.mjs.map +1 -1
- package/dist/parseSpEL.d.mts +3 -2
- package/dist/parseSpEL.d.ts +3 -2
- package/dist/parseSpEL.js +7 -9
- package/dist/parseSpEL.js.map +1 -1
- package/dist/parseSpEL.mjs +5 -6
- package/dist/parseSpEL.mjs.map +1 -1
- package/dist/{prepareQueryObjects-BqFEs4eV.js → prepareQueryObjects-BOUWfel5.js} +4 -5
- package/dist/prepareQueryObjects-BOUWfel5.js.map +1 -0
- package/dist/{prepareQueryObjects-CS6Wmhmf.mjs → prepareQueryObjects-CJNpnGcJ.mjs} +5 -6
- package/dist/prepareQueryObjects-CJNpnGcJ.mjs.map +1 -0
- package/dist/query-builder-layout.css +1 -1
- package/dist/query-builder-layout.css.map +1 -1
- package/dist/query-builder.css +1 -1
- package/dist/query-builder.css.map +1 -1
- package/dist/react-querybuilder_core.d.mts +553 -1247
- package/dist/react-querybuilder_core.legacy-esm.d.ts +553 -1247
- package/dist/react-querybuilder_core.legacy-esm.js +412 -119
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +405 -122
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +553 -1247
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/dist/styles/_layout.scss +61 -17
- package/dist/styles/_main.scss +17 -4
- package/dist/{transformQuery-FL_nlpp5.js → transformQuery-CWDPogO5.js} +1 -1
- package/dist/{transformQuery-FL_nlpp5.js.map → transformQuery-CWDPogO5.js.map} +1 -1
- package/dist/{transformQuery-DdMvmrCh.mjs → transformQuery-DHvtgDgZ.mjs} +2 -2
- package/dist/{transformQuery-DdMvmrCh.mjs.map → transformQuery-DHvtgDgZ.mjs.map} +1 -1
- package/dist/transformQuery.d.mts +1 -1
- package/dist/transformQuery.d.ts +1 -1
- package/dist/transformQuery.js +1 -1
- package/dist/transformQuery.mjs +2 -2
- package/package.json +14 -12
- package/dist/arrayUtils-BF1P8iHS.mjs.map +0 -1
- package/dist/arrayUtils-D5EoIsKP.js +0 -164
- package/dist/arrayUtils-D5EoIsKP.js.map +0 -1
- package/dist/basic-BfD-7CN3.d.mts +0 -1235
- package/dist/basic-C8xXKHIA.d.ts +0 -1235
- package/dist/objectUtils-BBZSfZJz.js +0 -17
- package/dist/objectUtils-BBZSfZJz.js.map +0 -1
- package/dist/objectUtils-BtWdcZVG.mjs +0 -11
- package/dist/objectUtils-BtWdcZVG.mjs.map +0 -1
- package/dist/optGroupUtils-CXLgyg2i.js.map +0 -1
- package/dist/optGroupUtils-Duv-M8rf.mjs.map +0 -1
- package/dist/prepareQueryObjects-BqFEs4eV.js.map +0 -1
- package/dist/prepareQueryObjects-CS6Wmhmf.mjs.map +0 -1
|
@@ -2,59 +2,205 @@ import { JsonLogicAll, JsonLogicAnd, JsonLogicDoubleNegation, JsonLogicEqual, Js
|
|
|
2
2
|
import { Column, Operators, SQL, Table } from "drizzle-orm";
|
|
3
3
|
import { WhereOptions } from "sequelize";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../../node_modules/type-fest/source/primitive.d.ts
|
|
6
|
+
/**
|
|
7
|
+
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
8
|
+
|
|
9
|
+
@category Type
|
|
10
|
+
*/
|
|
11
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region ../../node_modules/type-fest/source/observable-like.d.ts
|
|
14
|
+
declare global {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
16
|
+
interface SymbolConstructor {
|
|
17
|
+
readonly observable: symbol;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
6
20
|
|
|
7
21
|
/**
|
|
8
|
-
|
|
22
|
+
@remarks
|
|
23
|
+
The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021.
|
|
24
|
+
As well, some guidance on making an `Observable` to not include `closed` property.
|
|
25
|
+
@see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
|
|
26
|
+
@see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
|
|
27
|
+
@see https://github.com/benlesh/symbol-observable#making-an-object-observable
|
|
9
28
|
|
|
10
|
-
@
|
|
11
|
-
|
|
29
|
+
@category Observable
|
|
30
|
+
*/
|
|
12
31
|
|
|
13
|
-
|
|
14
|
-
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region ../../node_modules/type-fest/source/union-to-intersection.d.ts
|
|
34
|
+
/**
|
|
35
|
+
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).
|
|
36
|
+
|
|
37
|
+
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
15
38
|
|
|
16
39
|
@example
|
|
17
40
|
```
|
|
18
|
-
import type {
|
|
41
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
19
42
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
44
|
+
|
|
45
|
+
type Intersection = UnionToIntersection<Union>;
|
|
46
|
+
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
A more applicable example which could make its way into your library code follows.
|
|
50
|
+
|
|
51
|
+
@example
|
|
52
|
+
```
|
|
53
|
+
import type {UnionToIntersection} from 'type-fest';
|
|
54
|
+
|
|
55
|
+
class CommandOne {
|
|
56
|
+
commands: {
|
|
57
|
+
a1: () => undefined,
|
|
58
|
+
b1: () => undefined,
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
class CommandTwo {
|
|
63
|
+
commands: {
|
|
64
|
+
a2: (argA: string) => undefined,
|
|
65
|
+
b2: (argB: string) => undefined,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
70
|
+
type Union = typeof union;
|
|
71
|
+
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
72
|
+
|
|
73
|
+
type Intersection = UnionToIntersection<Union>;
|
|
74
|
+
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
@category Type
|
|
78
|
+
*/
|
|
79
|
+
type UnionToIntersection<Union> = (
|
|
80
|
+
// `extends unknown` is always going to be the case and is used to convert the
|
|
81
|
+
// `Union` into a [distributive conditional
|
|
82
|
+
// type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
|
|
83
|
+
Union extends unknown
|
|
84
|
+
// The union type is used as the only argument to a function since the union
|
|
85
|
+
// of function arguments is an intersection.
|
|
86
|
+
? (distributedUnion: Union) => void
|
|
87
|
+
// This won't happen.
|
|
88
|
+
: never
|
|
89
|
+
// Infer the `Intersection` type since TypeScript represents the positional
|
|
90
|
+
// arguments of unions of functions as an intersection of the union.
|
|
91
|
+
) extends ((mergedIntersection: infer Intersection) => void)
|
|
92
|
+
// The `& Union` is to allow indexing by the resulting type
|
|
93
|
+
? Intersection & Union : never;
|
|
94
|
+
//#endregion
|
|
95
|
+
//#region ../../node_modules/type-fest/source/keys-of-union.d.ts
|
|
96
|
+
/**
|
|
97
|
+
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
98
|
+
|
|
99
|
+
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
100
|
+
|
|
101
|
+
@link https://stackoverflow.com/a/49402091
|
|
102
|
+
|
|
103
|
+
@example
|
|
104
|
+
```
|
|
105
|
+
import type {KeysOfUnion} from 'type-fest';
|
|
106
|
+
|
|
107
|
+
type A = {
|
|
108
|
+
common: string;
|
|
109
|
+
a: number;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
type B = {
|
|
113
|
+
common: string;
|
|
114
|
+
b: string;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
type C = {
|
|
118
|
+
common: string;
|
|
119
|
+
c: boolean;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type Union = A | B | C;
|
|
123
|
+
|
|
124
|
+
type CommonKeys = keyof Union;
|
|
125
|
+
//=> 'common'
|
|
126
|
+
|
|
127
|
+
type AllKeys = KeysOfUnion<Union>;
|
|
128
|
+
//=> 'common' | 'a' | 'b' | 'c'
|
|
28
129
|
```
|
|
29
130
|
|
|
30
|
-
@
|
|
131
|
+
@category Object
|
|
31
132
|
*/
|
|
32
|
-
type
|
|
133
|
+
type KeysOfUnion<ObjectType> =
|
|
134
|
+
// Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
|
|
135
|
+
keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
33
136
|
//#endregion
|
|
34
|
-
//#region
|
|
137
|
+
//#region ../../node_modules/type-fest/source/optional-keys-of.d.ts
|
|
35
138
|
/**
|
|
36
|
-
|
|
139
|
+
Extract all optional keys from the given type.
|
|
37
140
|
|
|
38
|
-
|
|
141
|
+
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
39
142
|
|
|
40
143
|
@example
|
|
41
144
|
```
|
|
42
|
-
import type {
|
|
145
|
+
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
43
146
|
|
|
44
|
-
|
|
45
|
-
|
|
147
|
+
interface User {
|
|
148
|
+
name: string;
|
|
149
|
+
surname: string;
|
|
46
150
|
|
|
47
|
-
|
|
48
|
-
|
|
151
|
+
luckyNumber?: number;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
155
|
+
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
156
|
+
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const update1: UpdateOperation<User> = {
|
|
160
|
+
name: 'Alice'
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const update2: UpdateOperation<User> = {
|
|
164
|
+
name: 'Bob',
|
|
165
|
+
luckyNumber: REMOVE_FIELD
|
|
166
|
+
};
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
@category Utilities
|
|
170
|
+
*/
|
|
171
|
+
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
172
|
+
? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
173
|
+
: never;
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region ../../node_modules/type-fest/source/required-keys-of.d.ts
|
|
176
|
+
/**
|
|
177
|
+
Extract all required keys from the given type.
|
|
178
|
+
|
|
179
|
+
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...
|
|
180
|
+
|
|
181
|
+
@example
|
|
49
182
|
```
|
|
183
|
+
import type {RequiredKeysOf} from 'type-fest';
|
|
184
|
+
|
|
185
|
+
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
186
|
+
|
|
187
|
+
interface User {
|
|
188
|
+
name: string;
|
|
189
|
+
surname: string;
|
|
190
|
+
|
|
191
|
+
luckyNumber?: number;
|
|
192
|
+
}
|
|
50
193
|
|
|
51
|
-
|
|
194
|
+
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
195
|
+
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
196
|
+
```
|
|
52
197
|
|
|
53
|
-
@
|
|
198
|
+
@category Utilities
|
|
54
199
|
*/
|
|
55
|
-
type
|
|
200
|
+
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
|
|
201
|
+
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
56
202
|
//#endregion
|
|
57
|
-
//#region
|
|
203
|
+
//#region ../../node_modules/type-fest/source/is-never.d.ts
|
|
58
204
|
/**
|
|
59
205
|
Returns a boolean for whether the given type is `never`.
|
|
60
206
|
|
|
@@ -70,20 +216,20 @@ import type {IsNever, And} from 'type-fest';
|
|
|
70
216
|
|
|
71
217
|
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
72
218
|
type AreStringsEqual<A extends string, B extends string> =
|
|
73
|
-
And<
|
|
74
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
75
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
76
|
-
>;
|
|
219
|
+
And<
|
|
220
|
+
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
221
|
+
IsNever<Exclude<B, A>> extends true ? true : false
|
|
222
|
+
>;
|
|
77
223
|
|
|
78
224
|
type EndIfEqual<I extends string, O extends string> =
|
|
79
|
-
AreStringsEqual<I, O> extends true
|
|
80
|
-
? never
|
|
81
|
-
: void;
|
|
225
|
+
AreStringsEqual<I, O> extends true
|
|
226
|
+
? never
|
|
227
|
+
: void;
|
|
82
228
|
|
|
83
229
|
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
84
|
-
if (input === output) {
|
|
85
|
-
process.exit(0);
|
|
86
|
-
}
|
|
230
|
+
if (input === output) {
|
|
231
|
+
process.exit(0);
|
|
232
|
+
}
|
|
87
233
|
}
|
|
88
234
|
|
|
89
235
|
endIfEqual('abc', 'abc');
|
|
@@ -93,11 +239,12 @@ endIfEqual('abc', '123');
|
|
|
93
239
|
//=> void
|
|
94
240
|
```
|
|
95
241
|
|
|
96
|
-
@
|
|
242
|
+
@category Type Guard
|
|
243
|
+
@category Utilities
|
|
97
244
|
*/
|
|
98
245
|
type IsNever<T> = [T] extends [never] ? true : false;
|
|
99
246
|
//#endregion
|
|
100
|
-
//#region
|
|
247
|
+
//#region ../../node_modules/type-fest/source/if-never.d.ts
|
|
101
248
|
/**
|
|
102
249
|
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
103
250
|
|
|
@@ -114,11 +261,12 @@ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
|
114
261
|
//=> 'bar'
|
|
115
262
|
```
|
|
116
263
|
|
|
117
|
-
@
|
|
264
|
+
@category Type Guard
|
|
265
|
+
@category Utilities
|
|
118
266
|
*/
|
|
119
267
|
type IfNever$1<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
|
|
120
268
|
//#endregion
|
|
121
|
-
//#region
|
|
269
|
+
//#region ../../node_modules/type-fest/source/unknown-array.d.ts
|
|
122
270
|
/**
|
|
123
271
|
Represents an array with `unknown` value.
|
|
124
272
|
|
|
@@ -140,16 +288,15 @@ type C = IsArray<string>;
|
|
|
140
288
|
//=> false
|
|
141
289
|
```
|
|
142
290
|
|
|
143
|
-
@
|
|
291
|
+
@category Type
|
|
292
|
+
@category Array
|
|
144
293
|
*/
|
|
145
294
|
type UnknownArray = readonly unknown[];
|
|
146
295
|
//#endregion
|
|
147
|
-
//#region
|
|
296
|
+
//#region ../../node_modules/type-fest/source/internal/array.d.ts
|
|
148
297
|
|
|
149
298
|
/**
|
|
150
299
|
Returns whether the given array `T` is readonly.
|
|
151
|
-
|
|
152
|
-
@group type-fest
|
|
153
300
|
*/
|
|
154
301
|
type IsArrayReadonly<T extends UnknownArray> = IfNever$1<T, false, T extends unknown[] ? false : true>;
|
|
155
302
|
/**
|
|
@@ -162,9 +309,9 @@ An if-else-like type that resolves depending on whether the given array is reado
|
|
|
162
309
|
import type {ArrayTail} from 'type-fest';
|
|
163
310
|
|
|
164
311
|
type ReadonlyPreservingArrayTail<TArray extends readonly unknown[]> =
|
|
165
|
-
ArrayTail<TArray> extends infer Tail
|
|
166
|
-
? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
|
|
167
|
-
: never;
|
|
312
|
+
ArrayTail<TArray> extends infer Tail
|
|
313
|
+
? IfArrayReadonly<TArray, Readonly<Tail>, Tail>
|
|
314
|
+
: never;
|
|
168
315
|
|
|
169
316
|
type ReadonlyTail = ReadonlyPreservingArrayTail<readonly [string, number, boolean]>;
|
|
170
317
|
//=> readonly [number, boolean]
|
|
@@ -178,19 +325,14 @@ type ShouldBeTrue = IfArrayReadonly<readonly unknown[]>;
|
|
|
178
325
|
type ShouldBeBar = IfArrayReadonly<unknown[], 'foo', 'bar'>;
|
|
179
326
|
//=> 'bar'
|
|
180
327
|
```
|
|
181
|
-
|
|
182
|
-
@group type-fest
|
|
183
328
|
*/
|
|
184
329
|
type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> = IsArrayReadonly<T> extends infer Result ? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly : never;
|
|
185
330
|
//#endregion
|
|
186
|
-
//#region
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*/
|
|
190
|
-
type Whitespace = " " | "\n" | "\v" | "\f" | "\r" | " " | "
" | "\xA0" | " " | " " | " " | " " | " " | " " | " " | " " | " " | " " | " " | " " | "\u2028" | "\u2029" | " " | " " | " " | "";
|
|
191
|
-
//#endregion
|
|
192
|
-
//#region src/types/type-fest/is-any.d.ts
|
|
331
|
+
//#region ../../node_modules/type-fest/source/is-any.d.ts
|
|
332
|
+
// Can eventually be replaced with the built-in once this library supports
|
|
333
|
+
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
193
334
|
type NoInfer<T> = T extends infer U ? U : never;
|
|
335
|
+
|
|
194
336
|
/**
|
|
195
337
|
Returns a boolean for whether the given type is `any`.
|
|
196
338
|
|
|
@@ -206,809 +348,51 @@ const typedObject = {a: 1, b: 2} as const;
|
|
|
206
348
|
const anyObject: any = {a: 1, b: 2};
|
|
207
349
|
|
|
208
350
|
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
209
|
-
return obj[key];
|
|
351
|
+
return obj[key];
|
|
210
352
|
}
|
|
211
353
|
|
|
212
354
|
const typedA = get(typedObject, 'a');
|
|
213
355
|
//=> 1
|
|
214
356
|
|
|
215
|
-
const anyA = get(anyObject, 'a');
|
|
216
|
-
//=> any
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
@group type-fest
|
|
220
|
-
*/
|
|
221
|
-
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
222
|
-
//#endregion
|
|
223
|
-
//#region src/types/type-fest/primitive.d.ts
|
|
224
|
-
/**
|
|
225
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
226
|
-
|
|
227
|
-
@group type-fest
|
|
228
|
-
*/
|
|
229
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
230
|
-
//#endregion
|
|
231
|
-
//#region src/types/type-fest/is-float.d.ts
|
|
232
|
-
/**
|
|
233
|
-
Returns a boolean for whether the given number is a float, like `1.5` or `-1.5`.
|
|
234
|
-
|
|
235
|
-
Use-case:
|
|
236
|
-
- If you want to make a conditional branch based on the result of whether a number is a float or not.
|
|
237
|
-
|
|
238
|
-
@example
|
|
239
|
-
```
|
|
240
|
-
import type {IsFloat, PositiveInfinity} from "type-fest";
|
|
241
|
-
|
|
242
|
-
type A = IsFloat<1.5>;
|
|
243
|
-
//=> true
|
|
244
|
-
|
|
245
|
-
type B = IsFloat<-1.5>;
|
|
246
|
-
//=> true
|
|
247
|
-
|
|
248
|
-
type C = IsFloat<1e-7>;
|
|
249
|
-
//=> true
|
|
250
|
-
|
|
251
|
-
type D = IsFloat<1.0>;
|
|
252
|
-
//=> false
|
|
253
|
-
|
|
254
|
-
type E = IsFloat<PositiveInfinity>;
|
|
255
|
-
//=> false
|
|
256
|
-
|
|
257
|
-
type F = IsFloat<1.23e+21>;
|
|
258
|
-
//=> false
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
@group type-fest
|
|
262
|
-
*/
|
|
263
|
-
type IsFloat<T> = T extends number ? `${T}` extends `${number}e${infer E extends "-" | "+"}${number}` ? E extends "-" ? true : false : `${T}` extends `${number}.${number}` ? true : false : false;
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/types/type-fest/is-integer.d.ts
|
|
266
|
-
/**
|
|
267
|
-
Returns a boolean for whether the given number is an integer, like `-5`, `1.0`, or `100`.
|
|
268
|
-
|
|
269
|
-
Use-case:
|
|
270
|
-
- If you want to make a conditional branch based on the result of whether a number is an integer or not.
|
|
271
|
-
|
|
272
|
-
@example
|
|
273
|
-
```
|
|
274
|
-
import type {IsInteger, PositiveInfinity} from "type-fest";
|
|
275
|
-
|
|
276
|
-
type A = IsInteger<1>;
|
|
277
|
-
//=> true
|
|
278
|
-
|
|
279
|
-
type B = IsInteger<1.0>;
|
|
280
|
-
//=> true
|
|
281
|
-
|
|
282
|
-
type C = IsInteger<-1>;
|
|
283
|
-
//=> true
|
|
284
|
-
|
|
285
|
-
type D = IsInteger<0b10>;
|
|
286
|
-
//=> true
|
|
287
|
-
|
|
288
|
-
type E = IsInteger<0o10>;
|
|
289
|
-
//=> true
|
|
290
|
-
|
|
291
|
-
type F = IsInteger<0x10>;
|
|
292
|
-
//=> true
|
|
293
|
-
|
|
294
|
-
type G = IsInteger<1.23+21>;
|
|
295
|
-
//=> true
|
|
296
|
-
|
|
297
|
-
type H = IsInteger<1.5>;
|
|
298
|
-
//=> false
|
|
299
|
-
|
|
300
|
-
type I = IsInteger<PositiveInfinity>;
|
|
301
|
-
//=> false
|
|
302
|
-
|
|
303
|
-
type J = IsInteger<1e-7>;
|
|
304
|
-
//=> false
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
@group type-fest
|
|
308
|
-
*/
|
|
309
|
-
type IsInteger<T> = T extends bigint ? true : T extends number ? number extends T ? false : T extends PositiveInfinity | NegativeInfinity ? false : Not<IsFloat<T>> : false;
|
|
310
|
-
//#endregion
|
|
311
|
-
//#region src/types/type-fest/numeric.d.ts
|
|
312
|
-
/**
|
|
313
|
-
@group type-fest
|
|
314
|
-
*/
|
|
315
|
-
type Numeric = number | bigint;
|
|
316
|
-
/**
|
|
317
|
-
@group type-fest
|
|
318
|
-
*/
|
|
319
|
-
type Zero = 0 | 0n;
|
|
320
|
-
/**
|
|
321
|
-
Matches the hidden `Infinity` type.
|
|
322
|
-
|
|
323
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
324
|
-
|
|
325
|
-
@see NegativeInfinity
|
|
326
|
-
|
|
327
|
-
@group type-fest
|
|
328
|
-
*/
|
|
329
|
-
type PositiveInfinity = 1e999;
|
|
330
|
-
/**
|
|
331
|
-
Matches the hidden `-Infinity` type.
|
|
332
|
-
|
|
333
|
-
Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
|
|
334
|
-
|
|
335
|
-
@see PositiveInfinity
|
|
336
|
-
|
|
337
|
-
@group type-fest
|
|
338
|
-
*/
|
|
339
|
-
type NegativeInfinity = -1e999;
|
|
340
|
-
/**
|
|
341
|
-
A finite `number`.
|
|
342
|
-
You can't pass a `bigint` as they are already guaranteed to be finite.
|
|
343
|
-
|
|
344
|
-
Use-case: Validating and documenting parameters.
|
|
345
|
-
|
|
346
|
-
Note: This can't detect `NaN`, please upvote [this issue](https://github.com/microsoft/TypeScript/issues/28682) if you want to have this type as a built-in in TypeScript.
|
|
347
|
-
|
|
348
|
-
@example
|
|
349
|
-
```
|
|
350
|
-
import type {Finite} from 'type-fest';
|
|
351
|
-
|
|
352
|
-
declare function setScore<T extends number>(length: Finite<T>): void;
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
@group type-fest
|
|
356
|
-
*/
|
|
357
|
-
type Finite<T extends number> = T extends PositiveInfinity | NegativeInfinity ? never : T;
|
|
358
|
-
/**
|
|
359
|
-
A `number` that is an integer.
|
|
360
|
-
|
|
361
|
-
Use-case: Validating and documenting parameters.
|
|
362
|
-
|
|
363
|
-
@example
|
|
364
|
-
```
|
|
365
|
-
type Integer = Integer<1>;
|
|
366
|
-
//=> 1
|
|
367
|
-
|
|
368
|
-
type IntegerWithDecimal = Integer<1.0>;
|
|
369
|
-
//=> 1
|
|
370
|
-
|
|
371
|
-
type NegativeInteger = Integer<-1>;
|
|
372
|
-
//=> -1
|
|
373
|
-
|
|
374
|
-
type Float = Integer<1.5>;
|
|
375
|
-
//=> never
|
|
376
|
-
|
|
377
|
-
// Supports non-decimal numbers
|
|
378
|
-
|
|
379
|
-
type OctalInteger: Integer<0o10>;
|
|
380
|
-
//=> 0o10
|
|
381
|
-
|
|
382
|
-
type BinaryInteger: Integer<0b10>;
|
|
383
|
-
//=> 0b10
|
|
384
|
-
|
|
385
|
-
type HexadecimalInteger: Integer<0x10>;
|
|
386
|
-
//=> 0x10
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
@example
|
|
390
|
-
```
|
|
391
|
-
import type {Integer} from 'type-fest';
|
|
392
|
-
|
|
393
|
-
declare function setYear<T extends number>(length: Integer<T>): void;
|
|
394
|
-
```
|
|
395
|
-
|
|
396
|
-
@see NegativeInteger
|
|
397
|
-
@see NonNegativeInteger
|
|
398
|
-
|
|
399
|
-
@group type-fest
|
|
400
|
-
*/
|
|
401
|
-
type Integer<T> = T extends unknown ? IsInteger<T> extends true ? T : never : never;
|
|
402
|
-
/**
|
|
403
|
-
A `number` that is not an integer.
|
|
404
|
-
|
|
405
|
-
Use-case: Validating and documenting parameters.
|
|
406
|
-
|
|
407
|
-
It does not accept `Infinity`.
|
|
408
|
-
|
|
409
|
-
@example
|
|
410
|
-
```
|
|
411
|
-
import type {Float} from 'type-fest';
|
|
412
|
-
|
|
413
|
-
declare function setPercentage<T extends number>(length: Float<T>): void;
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
@see Integer
|
|
417
|
-
|
|
418
|
-
@group type-fest
|
|
419
|
-
*/
|
|
420
|
-
type Float<T> = T extends unknown ? IsFloat<T> extends true ? T : never : never;
|
|
421
|
-
/**
|
|
422
|
-
A negative (`-∞ < x < 0`) `number` that is not an integer.
|
|
423
|
-
Equivalent to `Negative<Float<T>>`.
|
|
424
|
-
|
|
425
|
-
Use-case: Validating and documenting parameters.
|
|
426
|
-
|
|
427
|
-
@see Negative
|
|
428
|
-
@see Float
|
|
429
|
-
|
|
430
|
-
@group type-fest
|
|
431
|
-
*/
|
|
432
|
-
type NegativeFloat<T extends number> = Negative<Float<T>>;
|
|
433
|
-
/**
|
|
434
|
-
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
435
|
-
|
|
436
|
-
Use-case: Validating and documenting parameters.
|
|
437
|
-
|
|
438
|
-
@see NegativeInteger
|
|
439
|
-
@see NonNegative
|
|
440
|
-
|
|
441
|
-
@group type-fest
|
|
442
|
-
*/
|
|
443
|
-
type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
444
|
-
/**
|
|
445
|
-
A negative (`-∞ < x < 0`) `number` that is an integer.
|
|
446
|
-
Equivalent to `Negative<Integer<T>>`.
|
|
447
|
-
|
|
448
|
-
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative<T>`.
|
|
449
|
-
|
|
450
|
-
Use-case: Validating and documenting parameters.
|
|
451
|
-
|
|
452
|
-
@see Negative
|
|
453
|
-
@see Integer
|
|
454
|
-
|
|
455
|
-
@group type-fest
|
|
456
|
-
*/
|
|
457
|
-
type NegativeInteger<T extends number> = Negative<Integer<T>>;
|
|
458
|
-
/**
|
|
459
|
-
A non-negative `number`/`bigint` (`0 <= x < ∞`).
|
|
460
|
-
|
|
461
|
-
Use-case: Validating and documenting parameters.
|
|
462
|
-
|
|
463
|
-
@see NonNegativeInteger
|
|
464
|
-
@see Negative
|
|
465
|
-
|
|
466
|
-
@example
|
|
467
|
-
```
|
|
468
|
-
import type {NonNegative} from 'type-fest';
|
|
469
|
-
|
|
470
|
-
declare function setLength<T extends number>(length: NonNegative<T>): void;
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
@group type-fest
|
|
474
|
-
*/
|
|
475
|
-
type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
|
|
476
|
-
/**
|
|
477
|
-
A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
|
478
|
-
Equivalent to `NonNegative<Integer<T>>`.
|
|
479
|
-
|
|
480
|
-
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative<T>`.
|
|
481
|
-
|
|
482
|
-
Use-case: Validating and documenting parameters.
|
|
483
|
-
|
|
484
|
-
@see NonNegative
|
|
485
|
-
@see Integer
|
|
486
|
-
|
|
487
|
-
@example
|
|
488
|
-
```
|
|
489
|
-
import type {NonNegativeInteger} from 'type-fest';
|
|
490
|
-
|
|
491
|
-
declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
@group type-fest
|
|
495
|
-
*/
|
|
496
|
-
type NonNegativeInteger<T extends number> = NonNegative<Integer<T>>;
|
|
497
|
-
/**
|
|
498
|
-
Returns a boolean for whether the given number is a negative number.
|
|
499
|
-
|
|
500
|
-
@see Negative
|
|
501
|
-
|
|
502
|
-
@example
|
|
503
|
-
```
|
|
504
|
-
import type {IsNegative} from 'type-fest';
|
|
505
|
-
|
|
506
|
-
type ShouldBeFalse = IsNegative<1>;
|
|
507
|
-
type ShouldBeTrue = IsNegative<-1>;
|
|
508
|
-
```
|
|
509
|
-
|
|
510
|
-
@group type-fest
|
|
511
|
-
*/
|
|
512
|
-
type IsNegative<T extends Numeric> = T extends Negative<T> ? true : false;
|
|
513
|
-
//#endregion
|
|
514
|
-
//#region src/types/type-fest/is-literal.d.ts
|
|
515
|
-
/**
|
|
516
|
-
Returns a boolean for whether the given type `T` is the specified `LiteralType`.
|
|
517
|
-
|
|
518
|
-
@link https://stackoverflow.com/a/52806744/10292952
|
|
519
|
-
|
|
520
|
-
@example
|
|
521
|
-
```
|
|
522
|
-
LiteralCheck<1, number>
|
|
523
|
-
//=> true
|
|
524
|
-
|
|
525
|
-
LiteralCheck<number, number>
|
|
526
|
-
//=> false
|
|
527
|
-
|
|
528
|
-
LiteralCheck<1, string>
|
|
529
|
-
//=> false
|
|
530
|
-
```
|
|
531
|
-
*/
|
|
532
|
-
type LiteralCheck<T, LiteralType extends Primitive> = (IsNever<T> extends false ? [T] extends [LiteralType & infer U] ? [U] extends [LiteralType] ? [LiteralType] extends [U] ? false : true : false : false : false);
|
|
533
|
-
/**
|
|
534
|
-
Returns a boolean for whether the given type `T` is one of the specified literal types in `LiteralUnionType`.
|
|
535
|
-
|
|
536
|
-
@example
|
|
537
|
-
```
|
|
538
|
-
LiteralChecks<1, Numeric>
|
|
539
|
-
//=> true
|
|
540
|
-
|
|
541
|
-
LiteralChecks<1n, Numeric>
|
|
542
|
-
//=> true
|
|
543
|
-
|
|
544
|
-
LiteralChecks<bigint, Numeric>
|
|
545
|
-
//=> false
|
|
546
|
-
```
|
|
547
|
-
*/
|
|
548
|
-
type LiteralChecks<T, LiteralUnionType> = (IsNotFalse<LiteralUnionType extends Primitive ? LiteralCheck<T, LiteralUnionType> : never>);
|
|
549
|
-
/**
|
|
550
|
-
Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
551
|
-
|
|
552
|
-
Useful for:
|
|
553
|
-
- providing strongly-typed string manipulation functions
|
|
554
|
-
- constraining strings to be a string literal
|
|
555
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
556
|
-
|
|
557
|
-
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
558
|
-
|
|
559
|
-
@example
|
|
560
|
-
```
|
|
561
|
-
import type {IsStringLiteral} from 'type-fest';
|
|
562
|
-
|
|
563
|
-
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
|
564
|
-
|
|
565
|
-
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
|
566
|
-
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
|
567
|
-
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const output = capitalize('hello, world!');
|
|
571
|
-
//=> 'Hello, world!'
|
|
572
|
-
```
|
|
573
|
-
|
|
574
|
-
@example
|
|
575
|
-
```
|
|
576
|
-
// String types with infinite set of possible values return `false`.
|
|
577
|
-
|
|
578
|
-
import type {IsStringLiteral} from 'type-fest';
|
|
579
|
-
|
|
580
|
-
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
|
581
|
-
//=> false
|
|
582
|
-
|
|
583
|
-
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
|
584
|
-
//=> false
|
|
585
|
-
|
|
586
|
-
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
|
587
|
-
|
|
588
|
-
type Length<S extends string, Counter extends never[] = []> =
|
|
589
|
-
IsStringLiteral<S> extends false
|
|
590
|
-
? number // return `number` for infinite string types
|
|
591
|
-
: S extends `${string}${infer Tail}`
|
|
592
|
-
? Length<Tail, [...Counter, never]>
|
|
593
|
-
: Counter['length'];
|
|
594
|
-
|
|
595
|
-
type L1 = Length<Lowercase<string>>;
|
|
596
|
-
//=> number
|
|
597
|
-
|
|
598
|
-
type L2 = Length<`${number}`>;
|
|
599
|
-
//=> number
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
@group type-fest
|
|
603
|
-
*/
|
|
604
|
-
type IsStringLiteral<T> = IfNever$1<T, false, T extends string ? {} extends Record<T, never> ? false : true : false>;
|
|
605
|
-
/**
|
|
606
|
-
Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
607
|
-
|
|
608
|
-
Useful for:
|
|
609
|
-
- providing strongly-typed functions when given literal arguments
|
|
610
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
611
|
-
|
|
612
|
-
@example
|
|
613
|
-
```
|
|
614
|
-
import type {IsNumericLiteral} from 'type-fest';
|
|
615
|
-
|
|
616
|
-
// https://github.com/inocan-group/inferred-types/blob/master/src/types/boolean-logic/EndsWith.ts
|
|
617
|
-
type EndsWith<TValue, TEndsWith extends string> =
|
|
618
|
-
TValue extends string
|
|
619
|
-
? IsStringLiteral<TEndsWith> extends true
|
|
620
|
-
? IsStringLiteral<TValue> extends true
|
|
621
|
-
? TValue extends `${string}${TEndsWith}`
|
|
622
|
-
? true
|
|
623
|
-
: false
|
|
624
|
-
: boolean
|
|
625
|
-
: boolean
|
|
626
|
-
: TValue extends number
|
|
627
|
-
? IsNumericLiteral<TValue> extends true
|
|
628
|
-
? EndsWith<`${TValue}`, TEndsWith>
|
|
629
|
-
: false
|
|
630
|
-
: false;
|
|
631
|
-
|
|
632
|
-
function endsWith<Input extends string | number, End extends string>(input: Input, end: End) {
|
|
633
|
-
return `${input}`.endsWith(end) as EndsWith<Input, End>;
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
endsWith('abc', 'c');
|
|
637
|
-
//=> true
|
|
638
|
-
|
|
639
|
-
endsWith(123456, '456');
|
|
640
|
-
//=> true
|
|
641
|
-
|
|
642
|
-
const end = '123' as string;
|
|
643
|
-
|
|
644
|
-
endsWith('abc123', end);
|
|
645
|
-
//=> boolean
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
@group type-fest
|
|
649
|
-
*/
|
|
650
|
-
type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
|
|
651
|
-
/**
|
|
652
|
-
Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
653
|
-
|
|
654
|
-
Useful for:
|
|
655
|
-
- providing strongly-typed functions when given literal arguments
|
|
656
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
657
|
-
|
|
658
|
-
@example
|
|
659
|
-
```
|
|
660
|
-
import type {IsBooleanLiteral} from 'type-fest';
|
|
661
|
-
|
|
662
|
-
const id = 123;
|
|
663
|
-
|
|
664
|
-
type GetId<AsString extends boolean> =
|
|
665
|
-
IsBooleanLiteral<AsString> extends true
|
|
666
|
-
? AsString extends true
|
|
667
|
-
? `${typeof id}`
|
|
668
|
-
: typeof id
|
|
669
|
-
: number | string;
|
|
670
|
-
|
|
671
|
-
function getId<AsString extends boolean = false>(options?: {asString: AsString}) {
|
|
672
|
-
return (options?.asString ? `${id}` : id) as GetId<AsString>;
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const numberId = getId();
|
|
676
|
-
//=> 123
|
|
677
|
-
|
|
678
|
-
const stringId = getId({asString: true});
|
|
679
|
-
//=> '123'
|
|
680
|
-
|
|
681
|
-
declare const runtimeBoolean: boolean;
|
|
682
|
-
const eitherId = getId({asString: runtimeBoolean});
|
|
683
|
-
//=> number | string
|
|
684
|
-
```
|
|
685
|
-
|
|
686
|
-
@group type-fest
|
|
687
|
-
*/
|
|
688
|
-
type IsBooleanLiteral<T> = LiteralCheck<T, boolean>;
|
|
689
|
-
/**
|
|
690
|
-
Returns a boolean for whether the given type is a `symbol` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
691
|
-
|
|
692
|
-
Useful for:
|
|
693
|
-
- providing strongly-typed functions when given literal arguments
|
|
694
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
695
|
-
|
|
696
|
-
@example
|
|
697
|
-
```
|
|
698
|
-
import type {IsSymbolLiteral} from 'type-fest';
|
|
699
|
-
|
|
700
|
-
type Get<Obj extends Record<symbol, number>, Key extends keyof Obj> =
|
|
701
|
-
IsSymbolLiteral<Key> extends true
|
|
702
|
-
? Obj[Key]
|
|
703
|
-
: number;
|
|
704
|
-
|
|
705
|
-
function get<Obj extends Record<symbol, number>, Key extends keyof Obj>(o: Obj, key: Key) {
|
|
706
|
-
return o[key] as Get<Obj, Key>;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
const symbolLiteral = Symbol('literal');
|
|
710
|
-
const symbolValue: symbol = Symbol('value');
|
|
711
|
-
|
|
712
|
-
get({[symbolLiteral]: 1} as const, symbolLiteral);
|
|
713
|
-
//=> 1
|
|
714
|
-
|
|
715
|
-
get({[symbolValue]: 1} as const, symbolValue);
|
|
716
|
-
//=> number
|
|
717
|
-
```
|
|
718
|
-
|
|
719
|
-
@group type-fest
|
|
720
|
-
*/
|
|
721
|
-
type IsSymbolLiteral<T> = LiteralCheck<T, symbol>;
|
|
722
|
-
/** Helper type for `IsLiteral`. */
|
|
723
|
-
type IsLiteralUnion<T> = IsStringLiteral<T> | IsNumericLiteral<T> | IsBooleanLiteral<T> | IsSymbolLiteral<T>;
|
|
724
|
-
/**
|
|
725
|
-
Returns a boolean for whether the given type is a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
726
|
-
|
|
727
|
-
Useful for:
|
|
728
|
-
- providing strongly-typed functions when given literal arguments
|
|
729
|
-
- type utilities, such as when constructing parsers and ASTs
|
|
730
|
-
|
|
731
|
-
@example
|
|
732
|
-
```
|
|
733
|
-
import type {IsLiteral} from 'type-fest';
|
|
734
|
-
|
|
735
|
-
// https://github.com/inocan-group/inferred-types/blob/master/src/types/string-literals/StripLeading.ts
|
|
736
|
-
export type StripLeading<A, B> =
|
|
737
|
-
A extends string
|
|
738
|
-
? B extends string
|
|
739
|
-
? IsLiteral<A> extends true
|
|
740
|
-
? string extends B ? never : A extends `${B & string}${infer After}` ? After : A
|
|
741
|
-
: string
|
|
742
|
-
: A
|
|
743
|
-
: A;
|
|
744
|
-
|
|
745
|
-
function stripLeading<Input extends string, Strip extends string>(input: Input, strip: Strip) {
|
|
746
|
-
return input.replace(`^${strip}`, '') as StripLeading<Input, Strip>;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
stripLeading('abc123', 'abc');
|
|
750
|
-
//=> '123'
|
|
751
|
-
|
|
752
|
-
const str = 'abc123' as string;
|
|
753
|
-
|
|
754
|
-
stripLeading(str, 'abc');
|
|
755
|
-
//=> string
|
|
756
|
-
```
|
|
757
|
-
|
|
758
|
-
@group type-fest
|
|
759
|
-
*/
|
|
760
|
-
type IsLiteral<T> = IsPrimitive<T> extends true ? IsNotFalse<IsLiteralUnion<T>> : false;
|
|
761
|
-
//#endregion
|
|
762
|
-
//#region src/types/type-fest/trim.d.ts
|
|
763
|
-
/**
|
|
764
|
-
Remove spaces from the left side.
|
|
765
|
-
*/
|
|
766
|
-
type TrimLeft<V extends string> = V extends `${Whitespace}${infer R}` ? TrimLeft<R> : V;
|
|
767
|
-
/**
|
|
768
|
-
Remove spaces from the right side.
|
|
769
|
-
*/
|
|
770
|
-
type TrimRight<V extends string> = V extends `${infer R}${Whitespace}` ? TrimRight<R> : V;
|
|
771
|
-
/**
|
|
772
|
-
Remove leading and trailing spaces from a string.
|
|
773
|
-
|
|
774
|
-
@example
|
|
775
|
-
```
|
|
776
|
-
import type {Trim} from 'type-fest';
|
|
777
|
-
|
|
778
|
-
Trim<' foo '>
|
|
779
|
-
//=> 'foo'
|
|
780
|
-
```
|
|
781
|
-
|
|
782
|
-
@group type-fest
|
|
783
|
-
*/
|
|
784
|
-
type Trim<V extends string> = TrimLeft<TrimRight<V>>;
|
|
785
|
-
//#endregion
|
|
786
|
-
//#region src/types/type-fest/or.d.ts
|
|
787
|
-
/**
|
|
788
|
-
Returns a boolean for whether either of two given types are true.
|
|
789
|
-
|
|
790
|
-
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
|
|
791
|
-
|
|
792
|
-
@example
|
|
793
|
-
```
|
|
794
|
-
import type {Or} from 'type-fest';
|
|
795
|
-
|
|
796
|
-
Or<true, false>;
|
|
797
|
-
//=> true
|
|
798
|
-
|
|
799
|
-
Or<false, false>;
|
|
800
|
-
//=> false
|
|
801
|
-
```
|
|
802
|
-
|
|
803
|
-
@see {@link And}
|
|
804
|
-
|
|
805
|
-
@group type-fest
|
|
806
|
-
*/
|
|
807
|
-
type Or<A extends boolean, B extends boolean> = [A, B][number] extends false ? false : true extends [IsEqual<A, true>, IsEqual<B, true>][number] ? true : never;
|
|
808
|
-
//#endregion
|
|
809
|
-
//#region src/types/type-fest/greater-than.d.ts
|
|
810
|
-
/**
|
|
811
|
-
Returns a boolean for whether a given number is greater than another number.
|
|
812
|
-
|
|
813
|
-
@example
|
|
814
|
-
```
|
|
815
|
-
import type {GreaterThan} from 'type-fest';
|
|
816
|
-
|
|
817
|
-
GreaterThan<1, -5>;
|
|
818
|
-
//=> true
|
|
819
|
-
|
|
820
|
-
GreaterThan<1, 1>;
|
|
821
|
-
//=> false
|
|
822
|
-
|
|
823
|
-
GreaterThan<1, 5>;
|
|
824
|
-
//=> false
|
|
825
|
-
```
|
|
826
|
-
|
|
827
|
-
@group type-fest
|
|
828
|
-
*/
|
|
829
|
-
type GreaterThan<A extends number, B extends number> = A extends number ? B extends number ? number extends A | B ? never : [IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>, IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>] extends infer R extends [boolean, boolean, boolean, boolean] ? Or<And<IsEqual<R[0], true>, IsEqual<R[2], false>>, And<IsEqual<R[3], true>, IsEqual<R[1], false>>> extends true ? true : Or<And<IsEqual<R[1], true>, IsEqual<R[3], false>>, And<IsEqual<R[2], true>, IsEqual<R[0], false>>> extends true ? false : true extends R[number] ? false : [IsNegative<A>, IsNegative<B>] extends infer R extends [boolean, boolean] ? [true, false] extends R ? false : [false, true] extends R ? true : [false, false] extends R ? PositiveNumericStringGt<`${A}`, `${B}`> : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`> : never : never : never : never;
|
|
830
|
-
//#endregion
|
|
831
|
-
//#region src/types/type-fest/greater-than-or-equal.d.ts
|
|
832
|
-
/**
|
|
833
|
-
Returns a boolean for whether a given number is greater than or equal to another number.
|
|
834
|
-
|
|
835
|
-
@example
|
|
836
|
-
```
|
|
837
|
-
import type {GreaterThanOrEqual} from 'type-fest';
|
|
838
|
-
|
|
839
|
-
GreaterThanOrEqual<1, -5>;
|
|
840
|
-
//=> true
|
|
841
|
-
|
|
842
|
-
GreaterThanOrEqual<1, 1>;
|
|
843
|
-
//=> true
|
|
844
|
-
|
|
845
|
-
GreaterThanOrEqual<1, 5>;
|
|
846
|
-
//=> false
|
|
847
|
-
```
|
|
848
|
-
|
|
849
|
-
@group type-fest
|
|
850
|
-
*/
|
|
851
|
-
type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B ? never : A extends B ? true : GreaterThan<A, B>;
|
|
852
|
-
//#endregion
|
|
853
|
-
//#region src/types/type-fest/less-than.d.ts
|
|
854
|
-
/**
|
|
855
|
-
Returns a boolean for whether a given number is less than another number.
|
|
856
|
-
|
|
857
|
-
@example
|
|
858
|
-
```
|
|
859
|
-
import type {LessThan} from 'type-fest';
|
|
860
|
-
|
|
861
|
-
LessThan<1, -5>;
|
|
862
|
-
//=> false
|
|
863
|
-
|
|
864
|
-
LessThan<1, 1>;
|
|
865
|
-
//=> false
|
|
866
|
-
|
|
867
|
-
LessThan<1, 5>;
|
|
868
|
-
//=> true
|
|
869
|
-
```
|
|
870
|
-
|
|
871
|
-
@group type-fest
|
|
872
|
-
*/
|
|
873
|
-
type LessThan<A extends number, B extends number> = number extends A | B ? never : GreaterThanOrEqual<A, B> extends infer Result ? Result extends true ? false : true : never;
|
|
874
|
-
//#endregion
|
|
875
|
-
//#region src/types/type-fest/internal/tuple.d.ts
|
|
876
|
-
/**
|
|
877
|
-
Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
|
|
878
|
-
|
|
879
|
-
If `<Fill>` is not provided, it will default to `unknown`.
|
|
880
|
-
|
|
881
|
-
@link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
|
|
882
|
-
|
|
883
|
-
@group type-fest
|
|
884
|
-
*/
|
|
885
|
-
type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = []> = number extends L ? Fill[] : L extends T["length"] ? T : BuildTuple<L, Fill, [...T, Fill]>;
|
|
886
|
-
//#endregion
|
|
887
|
-
//#region src/types/type-fest/internal/string.d.ts
|
|
888
|
-
/**
|
|
889
|
-
Converts a numeric string to a number.
|
|
890
|
-
|
|
891
|
-
@example
|
|
892
|
-
```
|
|
893
|
-
type PositiveInt = StringToNumber<'1234'>;
|
|
894
|
-
//=> 1234
|
|
895
|
-
|
|
896
|
-
type NegativeInt = StringToNumber<'-1234'>;
|
|
897
|
-
//=> -1234
|
|
898
|
-
|
|
899
|
-
type PositiveFloat = StringToNumber<'1234.56'>;
|
|
900
|
-
//=> 1234.56
|
|
901
|
-
|
|
902
|
-
type NegativeFloat = StringToNumber<'-1234.56'>;
|
|
903
|
-
//=> -1234.56
|
|
904
|
-
|
|
905
|
-
type PositiveInfinity = StringToNumber<'Infinity'>;
|
|
906
|
-
//=> Infinity
|
|
907
|
-
|
|
908
|
-
type NegativeInfinity = StringToNumber<'-Infinity'>;
|
|
909
|
-
//=> -Infinity
|
|
910
|
-
```
|
|
911
|
-
|
|
912
|
-
@group type-fest
|
|
913
|
-
*/
|
|
914
|
-
type StringToNumber<S extends string> = S extends `${infer N extends number}` ? N : S extends "Infinity" ? PositiveInfinity : S extends "-Infinity" ? NegativeInfinity : never;
|
|
915
|
-
/**
|
|
916
|
-
Returns an array of the characters of the string.
|
|
917
|
-
|
|
918
|
-
@example
|
|
919
|
-
```
|
|
920
|
-
StringToArray<'abcde'>;
|
|
921
|
-
//=> ['a', 'b', 'c', 'd', 'e']
|
|
922
|
-
|
|
923
|
-
StringToArray<string>;
|
|
924
|
-
//=> never
|
|
925
|
-
```
|
|
926
|
-
|
|
927
|
-
@group type-fest
|
|
928
|
-
*/
|
|
929
|
-
type StringToArray<S extends string, Result extends string[] = []> = string extends S ? never : S extends `${infer F}${infer R}` ? StringToArray<R, [...Result, F]> : Result;
|
|
930
|
-
/**
|
|
931
|
-
Returns the length of the given string.
|
|
932
|
-
|
|
933
|
-
@example
|
|
934
|
-
```
|
|
935
|
-
StringLength<'abcde'>;
|
|
936
|
-
//=> 5
|
|
937
|
-
|
|
938
|
-
StringLength<string>;
|
|
939
|
-
//=> never
|
|
940
|
-
```
|
|
941
|
-
|
|
942
|
-
@group type-fest
|
|
943
|
-
*/
|
|
944
|
-
type StringLength<S extends string> = string extends S ? never : StringToArray<S>["length"];
|
|
945
|
-
/**
|
|
946
|
-
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both numeric strings and have the same length.
|
|
947
|
-
|
|
948
|
-
@example
|
|
949
|
-
```
|
|
950
|
-
SameLengthPositiveNumericStringGt<'50', '10'>;
|
|
951
|
-
//=> true
|
|
952
|
-
|
|
953
|
-
SameLengthPositiveNumericStringGt<'10', '10'>;
|
|
954
|
-
//=> false
|
|
955
|
-
```
|
|
956
|
-
*/
|
|
957
|
-
type SameLengthPositiveNumericStringGt<A extends string, B extends string> = A extends `${infer FirstA}${infer RestA}` ? B extends `${infer FirstB}${infer RestB}` ? FirstA extends FirstB ? SameLengthPositiveNumericStringGt<RestA, RestB> : PositiveNumericCharacterGt<FirstA, FirstB> : never : false;
|
|
958
|
-
type NumericString = "0123456789";
|
|
959
|
-
/**
|
|
960
|
-
Returns a boolean for whether `A` is greater than `B`, where `A` and `B` are both positive numeric strings.
|
|
961
|
-
|
|
962
|
-
@example
|
|
963
|
-
```
|
|
964
|
-
PositiveNumericStringGt<'500', '1'>;
|
|
965
|
-
//=> true
|
|
966
|
-
|
|
967
|
-
PositiveNumericStringGt<'1', '1'>;
|
|
968
|
-
//=> false
|
|
969
|
-
|
|
970
|
-
PositiveNumericStringGt<'1', '500'>;
|
|
971
|
-
//=> false
|
|
972
|
-
```
|
|
973
|
-
|
|
974
|
-
@group type-fest
|
|
975
|
-
*/
|
|
976
|
-
type PositiveNumericStringGt<A extends string, B extends string> = A extends B ? false : [BuildTuple<StringLength<A>, 0>, BuildTuple<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]] ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]] ? 0 extends Remain["length"] ? SameLengthPositiveNumericStringGt<A, B> : true : false : never;
|
|
977
|
-
/**
|
|
978
|
-
Returns a boolean for whether `A` represents a number greater than `B`, where `A` and `B` are both positive numeric characters.
|
|
979
|
-
|
|
980
|
-
@example
|
|
981
|
-
```
|
|
982
|
-
PositiveNumericCharacterGt<'5', '1'>;
|
|
983
|
-
//=> true
|
|
984
|
-
|
|
985
|
-
PositiveNumericCharacterGt<'1', '1'>;
|
|
986
|
-
//=> false
|
|
357
|
+
const anyA = get(anyObject, 'a');
|
|
358
|
+
//=> any
|
|
987
359
|
```
|
|
360
|
+
|
|
361
|
+
@category Type Guard
|
|
362
|
+
@category Utilities
|
|
988
363
|
*/
|
|
989
|
-
type
|
|
364
|
+
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
990
365
|
//#endregion
|
|
991
|
-
//#region
|
|
366
|
+
//#region ../../node_modules/type-fest/source/is-equal.d.ts
|
|
992
367
|
/**
|
|
993
|
-
Returns
|
|
368
|
+
Returns a boolean for whether the two given types are equal.
|
|
369
|
+
|
|
370
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
371
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
372
|
+
|
|
373
|
+
Use-cases:
|
|
374
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
994
375
|
|
|
995
376
|
@example
|
|
996
377
|
```
|
|
997
|
-
|
|
998
|
-
//=> 1
|
|
999
|
-
|
|
1000
|
-
NumberAbsolute<1>;
|
|
1001
|
-
//=> 1
|
|
378
|
+
import type {IsEqual} from 'type-fest';
|
|
1002
379
|
|
|
1003
|
-
|
|
1004
|
-
|
|
380
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
381
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
382
|
+
type Includes<Value extends readonly any[], Item> =
|
|
383
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
384
|
+
? IsEqual<Value[0], Item> extends true
|
|
385
|
+
? true
|
|
386
|
+
: Includes<rest, Item>
|
|
387
|
+
: false;
|
|
1005
388
|
```
|
|
1006
389
|
|
|
1007
|
-
@
|
|
390
|
+
@category Type Guard
|
|
391
|
+
@category Utilities
|
|
1008
392
|
*/
|
|
1009
|
-
type
|
|
393
|
+
type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
1010
394
|
//#endregion
|
|
1011
|
-
//#region
|
|
395
|
+
//#region ../../node_modules/type-fest/source/simplify.d.ts
|
|
1012
396
|
/**
|
|
1013
397
|
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.
|
|
1014
398
|
|
|
@@ -1017,13 +401,13 @@ Useful to flatten the type output to improve type hints shown in editors. And al
|
|
|
1017
401
|
import type {Simplify} from 'type-fest';
|
|
1018
402
|
|
|
1019
403
|
type PositionProps = {
|
|
1020
|
-
top: number;
|
|
1021
|
-
left: number;
|
|
404
|
+
top: number;
|
|
405
|
+
left: number;
|
|
1022
406
|
};
|
|
1023
407
|
|
|
1024
408
|
type SizeProps = {
|
|
1025
|
-
width: number;
|
|
1026
|
-
height: number;
|
|
409
|
+
width: number;
|
|
410
|
+
height: number;
|
|
1027
411
|
};
|
|
1028
412
|
|
|
1029
413
|
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
@@ -1039,15 +423,15 @@ If the type definition must be an interface (perhaps it was defined in a third-p
|
|
|
1039
423
|
import type {Simplify} from 'type-fest';
|
|
1040
424
|
|
|
1041
425
|
interface SomeInterface {
|
|
1042
|
-
foo: number;
|
|
1043
|
-
bar?: string;
|
|
1044
|
-
baz: number | undefined;
|
|
426
|
+
foo: number;
|
|
427
|
+
bar?: string;
|
|
428
|
+
baz: number | undefined;
|
|
1045
429
|
}
|
|
1046
430
|
|
|
1047
431
|
type SomeType = {
|
|
1048
|
-
foo: number;
|
|
1049
|
-
bar?: string;
|
|
1050
|
-
baz: number | undefined;
|
|
432
|
+
foo: number;
|
|
433
|
+
bar?: string;
|
|
434
|
+
baz: number | undefined;
|
|
1051
435
|
};
|
|
1052
436
|
|
|
1053
437
|
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
@@ -1064,163 +448,11 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
1064
448
|
|
|
1065
449
|
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
1066
450
|
@see SimplifyDeep
|
|
1067
|
-
|
|
1068
|
-
@group type-fest
|
|
451
|
+
@category Object
|
|
1069
452
|
*/
|
|
1070
453
|
type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
|
|
1071
454
|
//#endregion
|
|
1072
|
-
//#region
|
|
1073
|
-
/**
|
|
1074
|
-
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).
|
|
1075
|
-
|
|
1076
|
-
Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
|
|
1077
|
-
|
|
1078
|
-
@example
|
|
1079
|
-
```
|
|
1080
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
1081
|
-
|
|
1082
|
-
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
1083
|
-
|
|
1084
|
-
type Intersection = UnionToIntersection<Union>;
|
|
1085
|
-
//=> {the(): void; great(arg: string): void; escape: boolean};
|
|
1086
|
-
```
|
|
1087
|
-
|
|
1088
|
-
A more applicable example which could make its way into your library code follows.
|
|
1089
|
-
|
|
1090
|
-
@example
|
|
1091
|
-
```
|
|
1092
|
-
import type {UnionToIntersection} from 'type-fest';
|
|
1093
|
-
|
|
1094
|
-
class CommandOne {
|
|
1095
|
-
commands: {
|
|
1096
|
-
a1: () => undefined,
|
|
1097
|
-
b1: () => undefined,
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
class CommandTwo {
|
|
1102
|
-
commands: {
|
|
1103
|
-
a2: (argA: string) => undefined,
|
|
1104
|
-
b2: (argB: string) => undefined,
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
|
|
1109
|
-
type Union = typeof union;
|
|
1110
|
-
//=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
|
|
1111
|
-
|
|
1112
|
-
type Intersection = UnionToIntersection<Union>;
|
|
1113
|
-
//=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
|
|
1114
|
-
```
|
|
1115
|
-
|
|
1116
|
-
@group type-fest
|
|
1117
|
-
*/
|
|
1118
|
-
type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
|
|
1119
|
-
//#endregion
|
|
1120
|
-
//#region src/types/type-fest/keys-of-union.d.ts
|
|
1121
|
-
/**
|
|
1122
|
-
Create a union of all keys from a given type, even those exclusive to specific union members.
|
|
1123
|
-
|
|
1124
|
-
Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
|
|
1125
|
-
|
|
1126
|
-
@link https://stackoverflow.com/a/49402091
|
|
1127
|
-
|
|
1128
|
-
@example
|
|
1129
|
-
```
|
|
1130
|
-
import type {KeysOfUnion} from 'type-fest';
|
|
1131
|
-
|
|
1132
|
-
type A = {
|
|
1133
|
-
common: string;
|
|
1134
|
-
a: number;
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
type B = {
|
|
1138
|
-
common: string;
|
|
1139
|
-
b: string;
|
|
1140
|
-
};
|
|
1141
|
-
|
|
1142
|
-
type C = {
|
|
1143
|
-
common: string;
|
|
1144
|
-
c: boolean;
|
|
1145
|
-
};
|
|
1146
|
-
|
|
1147
|
-
type Union = A | B | C;
|
|
1148
|
-
|
|
1149
|
-
type CommonKeys = keyof Union;
|
|
1150
|
-
//=> 'common'
|
|
1151
|
-
|
|
1152
|
-
type AllKeys = KeysOfUnion<Union>;
|
|
1153
|
-
//=> 'common' | 'a' | 'b' | 'c'
|
|
1154
|
-
```
|
|
1155
|
-
|
|
1156
|
-
@group type-fest
|
|
1157
|
-
*/
|
|
1158
|
-
type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
|
|
1159
|
-
//#endregion
|
|
1160
|
-
//#region src/types/type-fest/optional-keys-of.d.ts
|
|
1161
|
-
/**
|
|
1162
|
-
Extract all optional keys from the given type.
|
|
1163
|
-
|
|
1164
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
1165
|
-
|
|
1166
|
-
@example
|
|
1167
|
-
```
|
|
1168
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
1169
|
-
|
|
1170
|
-
interface User {
|
|
1171
|
-
name: string;
|
|
1172
|
-
surname: string;
|
|
1173
|
-
|
|
1174
|
-
luckyNumber?: number;
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
1178
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
1179
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
1180
|
-
};
|
|
1181
|
-
|
|
1182
|
-
const update1: UpdateOperation<User> = {
|
|
1183
|
-
name: 'Alice'
|
|
1184
|
-
};
|
|
1185
|
-
|
|
1186
|
-
const update2: UpdateOperation<User> = {
|
|
1187
|
-
name: 'Bob',
|
|
1188
|
-
luckyNumber: REMOVE_FIELD
|
|
1189
|
-
};
|
|
1190
|
-
```
|
|
1191
|
-
|
|
1192
|
-
@group type-fest
|
|
1193
|
-
*/
|
|
1194
|
-
type OptionalKeysOf<BaseType extends object> = BaseType extends unknown ? (keyof { [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never }) & (keyof BaseType) : never;
|
|
1195
|
-
//#endregion
|
|
1196
|
-
//#region src/types/type-fest/required-keys-of.d.ts
|
|
1197
|
-
/**
|
|
1198
|
-
Extract all required keys from the given type.
|
|
1199
|
-
|
|
1200
|
-
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...
|
|
1201
|
-
|
|
1202
|
-
@example
|
|
1203
|
-
```
|
|
1204
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
1205
|
-
|
|
1206
|
-
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
1207
|
-
|
|
1208
|
-
interface User {
|
|
1209
|
-
name: string;
|
|
1210
|
-
surname: string;
|
|
1211
|
-
|
|
1212
|
-
luckyNumber?: number;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
1216
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
1217
|
-
```
|
|
1218
|
-
|
|
1219
|
-
@group type-fest
|
|
1220
|
-
*/
|
|
1221
|
-
type RequiredKeysOf<BaseType extends object> = BaseType extends unknown ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
|
|
1222
|
-
//#endregion
|
|
1223
|
-
//#region src/types/type-fest/omit-index-signature.d.ts
|
|
455
|
+
//#region ../../node_modules/type-fest/source/omit-index-signature.d.ts
|
|
1224
456
|
/**
|
|
1225
457
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
1226
458
|
|
|
@@ -1246,13 +478,13 @@ Instead of causing a type error like the above, you can also use a [conditional
|
|
|
1246
478
|
|
|
1247
479
|
```
|
|
1248
480
|
type Indexed = {} extends Record<string, unknown>
|
|
1249
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1250
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
481
|
+
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
482
|
+
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
1251
483
|
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
1252
484
|
|
|
1253
485
|
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
1254
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
1255
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
486
|
+
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
487
|
+
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
1256
488
|
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
1257
489
|
```
|
|
1258
490
|
|
|
@@ -1262,8 +494,8 @@ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-type
|
|
|
1262
494
|
import type {OmitIndexSignature} from 'type-fest';
|
|
1263
495
|
|
|
1264
496
|
type OmitIndexSignature<ObjectType> = {
|
|
1265
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
1266
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
497
|
+
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
498
|
+
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
1267
499
|
};
|
|
1268
500
|
```
|
|
1269
501
|
|
|
@@ -1273,12 +505,12 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
1273
505
|
import type {OmitIndexSignature} from 'type-fest';
|
|
1274
506
|
|
|
1275
507
|
type OmitIndexSignature<ObjectType> = {
|
|
1276
|
-
[KeyType in keyof ObjectType
|
|
1277
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
1278
|
-
as {} extends Record<KeyType, unknown>
|
|
1279
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
1280
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
1281
|
-
]: ObjectType[KeyType];
|
|
508
|
+
[KeyType in keyof ObjectType
|
|
509
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
510
|
+
as {} extends Record<KeyType, unknown>
|
|
511
|
+
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
512
|
+
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
513
|
+
]: ObjectType[KeyType];
|
|
1282
514
|
};
|
|
1283
515
|
```
|
|
1284
516
|
|
|
@@ -1289,19 +521,19 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
|
|
|
1289
521
|
import type {OmitIndexSignature} from 'type-fest';
|
|
1290
522
|
|
|
1291
523
|
interface Example {
|
|
1292
|
-
// These index signatures will be removed.
|
|
1293
|
-
[x: string]: any
|
|
1294
|
-
[x: number]: any
|
|
1295
|
-
[x: symbol]: any
|
|
1296
|
-
[x: `head-${string}`]: string
|
|
1297
|
-
[x: `${string}-tail`]: string
|
|
1298
|
-
[x: `head-${string}-tail`]: string
|
|
1299
|
-
[x: `${bigint}`]: string
|
|
1300
|
-
[x: `embedded-${number}`]: string
|
|
1301
|
-
|
|
1302
|
-
// These explicitly defined keys will remain.
|
|
1303
|
-
foo: 'bar';
|
|
1304
|
-
qux?: 'baz';
|
|
524
|
+
// These index signatures will be removed.
|
|
525
|
+
[x: string]: any
|
|
526
|
+
[x: number]: any
|
|
527
|
+
[x: symbol]: any
|
|
528
|
+
[x: `head-${string}`]: string
|
|
529
|
+
[x: `${string}-tail`]: string
|
|
530
|
+
[x: `head-${string}-tail`]: string
|
|
531
|
+
[x: `${bigint}`]: string
|
|
532
|
+
[x: `embedded-${number}`]: string
|
|
533
|
+
|
|
534
|
+
// These explicitly defined keys will remain.
|
|
535
|
+
foo: 'bar';
|
|
536
|
+
qux?: 'baz';
|
|
1305
537
|
}
|
|
1306
538
|
|
|
1307
539
|
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
@@ -1309,12 +541,11 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
1309
541
|
```
|
|
1310
542
|
|
|
1311
543
|
@see PickIndexSignature
|
|
1312
|
-
|
|
1313
|
-
@group type-fest
|
|
544
|
+
@category Object
|
|
1314
545
|
*/
|
|
1315
546
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
1316
547
|
//#endregion
|
|
1317
|
-
//#region
|
|
548
|
+
//#region ../../node_modules/type-fest/source/pick-index-signature.d.ts
|
|
1318
549
|
/**
|
|
1319
550
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
1320
551
|
|
|
@@ -1327,21 +558,21 @@ import type {PickIndexSignature} from 'type-fest';
|
|
|
1327
558
|
declare const symbolKey: unique symbol;
|
|
1328
559
|
|
|
1329
560
|
type Example = {
|
|
1330
|
-
// These index signatures will remain.
|
|
1331
|
-
[x: string]: unknown;
|
|
1332
|
-
[x: number]: unknown;
|
|
1333
|
-
[x: symbol]: unknown;
|
|
1334
|
-
[x: `head-${string}`]: string;
|
|
1335
|
-
[x: `${string}-tail`]: string;
|
|
1336
|
-
[x: `head-${string}-tail`]: string;
|
|
1337
|
-
[x: `${bigint}`]: string;
|
|
1338
|
-
[x: `embedded-${number}`]: string;
|
|
1339
|
-
|
|
1340
|
-
// These explicitly defined keys will be removed.
|
|
1341
|
-
['kebab-case-key']: string;
|
|
1342
|
-
[symbolKey]: string;
|
|
1343
|
-
foo: 'bar';
|
|
1344
|
-
qux?: 'baz';
|
|
561
|
+
// These index signatures will remain.
|
|
562
|
+
[x: string]: unknown;
|
|
563
|
+
[x: number]: unknown;
|
|
564
|
+
[x: symbol]: unknown;
|
|
565
|
+
[x: `head-${string}`]: string;
|
|
566
|
+
[x: `${string}-tail`]: string;
|
|
567
|
+
[x: `head-${string}-tail`]: string;
|
|
568
|
+
[x: `${bigint}`]: string;
|
|
569
|
+
[x: `embedded-${number}`]: string;
|
|
570
|
+
|
|
571
|
+
// These explicitly defined keys will be removed.
|
|
572
|
+
['kebab-case-key']: string;
|
|
573
|
+
[symbolKey]: string;
|
|
574
|
+
foo: 'bar';
|
|
575
|
+
qux?: 'baz';
|
|
1345
576
|
};
|
|
1346
577
|
|
|
1347
578
|
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
@@ -1358,13 +589,14 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
1358
589
|
```
|
|
1359
590
|
|
|
1360
591
|
@see OmitIndexSignature
|
|
1361
|
-
|
|
1362
|
-
@group type-fest
|
|
592
|
+
@category Object
|
|
1363
593
|
*/
|
|
1364
594
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
1365
595
|
//#endregion
|
|
1366
|
-
//#region
|
|
596
|
+
//#region ../../node_modules/type-fest/source/merge.d.ts
|
|
597
|
+
// Merges two objects without worrying about index signatures.
|
|
1367
598
|
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
599
|
+
|
|
1368
600
|
/**
|
|
1369
601
|
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
1370
602
|
|
|
@@ -1373,17 +605,17 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
|
|
|
1373
605
|
import type {Merge} from 'type-fest';
|
|
1374
606
|
|
|
1375
607
|
interface Foo {
|
|
1376
|
-
[x: string]: unknown;
|
|
1377
|
-
[x: number]: unknown;
|
|
1378
|
-
foo: string;
|
|
1379
|
-
bar: symbol;
|
|
608
|
+
[x: string]: unknown;
|
|
609
|
+
[x: number]: unknown;
|
|
610
|
+
foo: string;
|
|
611
|
+
bar: symbol;
|
|
1380
612
|
}
|
|
1381
613
|
|
|
1382
614
|
type Bar = {
|
|
1383
|
-
[x: number]: number;
|
|
1384
|
-
[x: symbol]: unknown;
|
|
1385
|
-
bar: Date;
|
|
1386
|
-
baz: boolean;
|
|
615
|
+
[x: number]: number;
|
|
616
|
+
[x: symbol]: unknown;
|
|
617
|
+
bar: Date;
|
|
618
|
+
baz: boolean;
|
|
1387
619
|
};
|
|
1388
620
|
|
|
1389
621
|
export type FooBar = Merge<Foo, Bar>;
|
|
@@ -1397,11 +629,11 @@ export type FooBar = Merge<Foo, Bar>;
|
|
|
1397
629
|
// }
|
|
1398
630
|
```
|
|
1399
631
|
|
|
1400
|
-
@
|
|
632
|
+
@category Object
|
|
1401
633
|
*/
|
|
1402
634
|
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
1403
635
|
//#endregion
|
|
1404
|
-
//#region
|
|
636
|
+
//#region ../../node_modules/type-fest/source/if-any.d.ts
|
|
1405
637
|
/**
|
|
1406
638
|
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
1407
639
|
|
|
@@ -1418,50 +650,30 @@ type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
|
1418
650
|
//=> 'bar'
|
|
1419
651
|
```
|
|
1420
652
|
|
|
1421
|
-
@
|
|
653
|
+
@category Type Guard
|
|
654
|
+
@category Utilities
|
|
1422
655
|
*/
|
|
1423
656
|
type IfAny$1<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
|
|
1424
657
|
//#endregion
|
|
1425
|
-
//#region
|
|
658
|
+
//#region ../../node_modules/type-fest/source/internal/type.d.ts
|
|
1426
659
|
/**
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
@group type-fest
|
|
660
|
+
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
1430
661
|
*/
|
|
1431
|
-
type
|
|
662
|
+
type BuiltIns = Primitive | void | Date | RegExp;
|
|
1432
663
|
/**
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
@example
|
|
1436
|
-
```
|
|
1437
|
-
IsPrimitive<'string'>
|
|
1438
|
-
//=> true
|
|
1439
|
-
|
|
1440
|
-
IsPrimitive<string>
|
|
1441
|
-
//=> true
|
|
664
|
+
Test if the given function has multiple call signatures.
|
|
1442
665
|
|
|
1443
|
-
|
|
1444
|
-
//=> false
|
|
1445
|
-
```
|
|
666
|
+
Needed to handle the case of a single call signature with properties.
|
|
1446
667
|
|
|
1447
|
-
|
|
668
|
+
Multiple call signatures cannot currently be supported due to a TypeScript limitation.
|
|
669
|
+
@see https://github.com/microsoft/TypeScript/issues/29732
|
|
1448
670
|
*/
|
|
1449
|
-
type
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
```
|
|
1455
|
-
Not<true>;
|
|
1456
|
-
//=> false
|
|
1457
|
-
|
|
1458
|
-
Not<false>;
|
|
1459
|
-
//=> true
|
|
1460
|
-
```
|
|
671
|
+
type HasMultipleCallSignatures<T extends (...arguments_: any[]) => unknown> = T extends {
|
|
672
|
+
(...arguments_: infer A): unknown;
|
|
673
|
+
(...arguments_: infer B): unknown;
|
|
674
|
+
} ? B extends A ? A extends B ? false : true : true : false;
|
|
675
|
+
// Should never happen
|
|
1461
676
|
|
|
1462
|
-
@group type-fest
|
|
1463
|
-
*/
|
|
1464
|
-
type Not<A extends boolean> = A extends true ? false : A extends false ? true : never;
|
|
1465
677
|
/**
|
|
1466
678
|
An if-else-like type that resolves depending on whether the given type is `any` or `never`.
|
|
1467
679
|
|
|
@@ -1479,12 +691,10 @@ type B = IfNotAnyOrNever<any, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
|
1479
691
|
type C = IfNotAnyOrNever<never, 'VALID', 'IS_ANY', 'IS_NEVER'>;
|
|
1480
692
|
//=> 'IS_NEVER'
|
|
1481
693
|
```
|
|
1482
|
-
|
|
1483
|
-
@group type-fest
|
|
1484
694
|
*/
|
|
1485
695
|
type IfNotAnyOrNever<T, IfNotAnyOrNever, IfAny = any, IfNever = never> = IsAny<T> extends true ? IfAny : IsNever<T> extends true ? IfNever : IfNotAnyOrNever;
|
|
1486
696
|
//#endregion
|
|
1487
|
-
//#region
|
|
697
|
+
//#region ../../node_modules/type-fest/source/internal/object.d.ts
|
|
1488
698
|
/**
|
|
1489
699
|
Works similar to the built-in `Pick` utility type, except for the following differences:
|
|
1490
700
|
- Distributes over union types and allows picking keys from any member of the union type.
|
|
@@ -1495,15 +705,15 @@ Works similar to the built-in `Pick` utility type, except for the following diff
|
|
|
1495
705
|
@example
|
|
1496
706
|
```
|
|
1497
707
|
type ImageUpload = {
|
|
1498
|
-
url: string;
|
|
1499
|
-
size: number;
|
|
1500
|
-
thumbnailUrl: string;
|
|
708
|
+
url: string;
|
|
709
|
+
size: number;
|
|
710
|
+
thumbnailUrl: string;
|
|
1501
711
|
};
|
|
1502
712
|
|
|
1503
713
|
type VideoUpload = {
|
|
1504
|
-
url: string;
|
|
1505
|
-
duration: number;
|
|
1506
|
-
encodingFormat: string;
|
|
714
|
+
url: string;
|
|
715
|
+
duration: number;
|
|
716
|
+
encodingFormat: string;
|
|
1507
717
|
};
|
|
1508
718
|
|
|
1509
719
|
// Distributes over union types and allows picking keys from any member of the union type
|
|
@@ -1521,8 +731,6 @@ type Any = HomomorphicPick<{a: 1; b: 2} | {c: 3}, any>;
|
|
|
1521
731
|
// Doesn't pick `number` from a `string` index signature
|
|
1522
732
|
type IndexSignature = HomomorphicPick<{[k: string]: unknown}, number>;
|
|
1523
733
|
//=> {}
|
|
1524
|
-
|
|
1525
|
-
@group type-fest
|
|
1526
734
|
*/
|
|
1527
735
|
type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = { [P in keyof T as Extract<P, Keys>]: T[P] };
|
|
1528
736
|
/**
|
|
@@ -1576,12 +784,11 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
1576
784
|
// ~~~~~~~~~~~~~~~~
|
|
1577
785
|
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
1578
786
|
```
|
|
1579
|
-
|
|
1580
|
-
@group type-fest
|
|
1581
787
|
*/
|
|
1582
|
-
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options
|
|
788
|
+
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny$1<SpecifiedOptions, Defaults, IfNever$1<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key] }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
789
|
+
>>;
|
|
1583
790
|
//#endregion
|
|
1584
|
-
//#region
|
|
791
|
+
//#region ../../node_modules/type-fest/source/except.d.ts
|
|
1585
792
|
/**
|
|
1586
793
|
Filter out keys from an object.
|
|
1587
794
|
|
|
@@ -1613,16 +820,15 @@ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ?
|
|
|
1613
820
|
type ExceptOptions = {
|
|
1614
821
|
/**
|
|
1615
822
|
Disallow assigning non-specified properties.
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
@default false
|
|
823
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
824
|
+
@default false
|
|
1620
825
|
*/
|
|
1621
826
|
requireExactProps?: boolean;
|
|
1622
827
|
};
|
|
1623
828
|
type DefaultExceptOptions = {
|
|
1624
829
|
requireExactProps: false;
|
|
1625
830
|
};
|
|
831
|
+
|
|
1626
832
|
/**
|
|
1627
833
|
Create a type from an object type without certain keys.
|
|
1628
834
|
|
|
@@ -1637,8 +843,8 @@ This type was proposed to the TypeScript team, which declined it, saying they pr
|
|
|
1637
843
|
import type {Except} from 'type-fest';
|
|
1638
844
|
|
|
1639
845
|
type Foo = {
|
|
1640
|
-
a: number;
|
|
1641
|
-
b: string;
|
|
846
|
+
a: number;
|
|
847
|
+
b: string;
|
|
1642
848
|
};
|
|
1643
849
|
|
|
1644
850
|
type FooWithoutA = Except<Foo, 'a'>;
|
|
@@ -1658,10 +864,10 @@ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
|
1658
864
|
// Consider the following example:
|
|
1659
865
|
|
|
1660
866
|
type UserData = {
|
|
1661
|
-
[metadata: string]: string;
|
|
1662
|
-
email: string;
|
|
1663
|
-
name: string;
|
|
1664
|
-
role: 'admin' | 'user';
|
|
867
|
+
[metadata: string]: string;
|
|
868
|
+
email: string;
|
|
869
|
+
name: string;
|
|
870
|
+
role: 'admin' | 'user';
|
|
1665
871
|
};
|
|
1666
872
|
|
|
1667
873
|
// `Omit` clearly doesn't behave as expected in this case:
|
|
@@ -1674,38 +880,12 @@ type PostPayload = Except<UserData, 'email'>;
|
|
|
1674
880
|
//=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
1675
881
|
```
|
|
1676
882
|
|
|
1677
|
-
@
|
|
883
|
+
@category Object
|
|
1678
884
|
*/
|
|
1679
885
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
1680
|
-
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options[
|
|
1681
|
-
//#endregion
|
|
1682
|
-
//#region src/types/type-fest/override-properties.d.ts
|
|
1683
|
-
/**
|
|
1684
|
-
Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.
|
|
1685
|
-
|
|
1686
|
-
This is useful when you want to override existing properties with a different type and make sure that these properties really exist in the original.
|
|
1687
|
-
|
|
1688
|
-
@example
|
|
1689
|
-
```
|
|
1690
|
-
type Foo = {
|
|
1691
|
-
a: string
|
|
1692
|
-
b: string
|
|
1693
|
-
}
|
|
1694
|
-
type Bar = OverrideProperties<Foo, {b: number}>
|
|
1695
|
-
//=> {a: string, b: number}
|
|
1696
|
-
|
|
1697
|
-
type Baz = OverrideProperties<Foo, {c: number}>
|
|
1698
|
-
// Error, type '{ c: number; }' does not satisfy the constraint '{ c: never; }'
|
|
1699
|
-
|
|
1700
|
-
type Fizz = OverrideProperties<Foo, {b: number; c: number}>
|
|
1701
|
-
// Error, type '{ b: number; c: number; }' does not satisfy the constraint '{ b: number; c: never; }'
|
|
1702
|
-
```
|
|
1703
|
-
|
|
1704
|
-
@group type-fest
|
|
1705
|
-
*/
|
|
1706
|
-
type OverrideProperties<TOriginal, TOverride extends Partial<Record<keyof TOriginal, unknown>> & { [Key in keyof TOverride]: Key extends keyof TOriginal ? TOverride[Key] : never }> = Merge<TOriginal, TOverride>;
|
|
886
|
+
type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = { [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType] } & (Options['requireExactProps'] extends true ? Partial<Record<KeysType, never>> : {});
|
|
1707
887
|
//#endregion
|
|
1708
|
-
//#region
|
|
888
|
+
//#region ../../node_modules/type-fest/source/require-at-least-one.d.ts
|
|
1709
889
|
/**
|
|
1710
890
|
Create a type that requires at least one of the given keys. The remaining keys are kept as is.
|
|
1711
891
|
|
|
@@ -1714,60 +894,81 @@ Create a type that requires at least one of the given keys. The remaining keys a
|
|
|
1714
894
|
import type {RequireAtLeastOne} from 'type-fest';
|
|
1715
895
|
|
|
1716
896
|
type Responder = {
|
|
1717
|
-
text?: () => string;
|
|
1718
|
-
json?: () => string;
|
|
1719
|
-
secure?: boolean;
|
|
897
|
+
text?: () => string;
|
|
898
|
+
json?: () => string;
|
|
899
|
+
secure?: boolean;
|
|
1720
900
|
};
|
|
1721
901
|
|
|
1722
902
|
const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
|
|
1723
|
-
json: () => '{"message": "ok"}',
|
|
1724
|
-
secure: true
|
|
903
|
+
json: () => '{"message": "ok"}',
|
|
904
|
+
secure: true
|
|
1725
905
|
};
|
|
1726
906
|
```
|
|
1727
907
|
|
|
1728
|
-
@
|
|
908
|
+
@category Object
|
|
1729
909
|
*/
|
|
1730
910
|
type RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = IfNotAnyOrNever<ObjectType, IfNever$1<KeysType, never, _RequireAtLeastOne<ObjectType, IfAny$1<KeysType, keyof ObjectType, KeysType>>>>;
|
|
1731
|
-
type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = {
|
|
911
|
+
type _RequireAtLeastOne<ObjectType, KeysType extends keyof ObjectType> = {
|
|
912
|
+
// For each `Key` in `KeysType` make a mapped type:
|
|
913
|
+
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> &
|
|
914
|
+
// 1. Make `Key`'s type required
|
|
915
|
+
// 2. Make all other keys in `KeysType` optional
|
|
916
|
+
Partial<Pick<ObjectType, Exclude<KeysType, Key>>> }[KeysType] &
|
|
917
|
+
// 3. Add the remaining keys not in `KeysType`
|
|
918
|
+
Except<ObjectType, KeysType>;
|
|
1732
919
|
//#endregion
|
|
1733
|
-
//#region
|
|
1734
|
-
|
|
1735
|
-
Create a type that makes the given keys non-nullable, where the remaining keys are kept as is.
|
|
920
|
+
//#region ../../node_modules/type-fest/source/required-deep.d.ts
|
|
921
|
+
type ExcludeUndefined<T> = Exclude<T, undefined>;
|
|
1736
922
|
|
|
1737
|
-
|
|
923
|
+
/**
|
|
924
|
+
Create a type from another type with all keys and nested keys set to required.
|
|
1738
925
|
|
|
1739
|
-
Use-
|
|
926
|
+
Use-cases:
|
|
927
|
+
- Creating optional configuration interfaces where the underlying implementation still requires all options to be fully specified.
|
|
928
|
+
- Modeling the resulting type after a deep merge with a set of defaults.
|
|
1740
929
|
|
|
1741
930
|
@example
|
|
1742
931
|
```
|
|
1743
|
-
import type {
|
|
1744
|
-
|
|
1745
|
-
type Foo = {
|
|
1746
|
-
a: number | null;
|
|
1747
|
-
b: string | undefined;
|
|
1748
|
-
c?: boolean | null;
|
|
1749
|
-
}
|
|
932
|
+
import type {RequiredDeep} from 'type-fest';
|
|
1750
933
|
|
|
1751
|
-
type
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
934
|
+
type Settings = {
|
|
935
|
+
textEditor?: {
|
|
936
|
+
fontSize?: number | undefined;
|
|
937
|
+
fontColor?: string | undefined;
|
|
938
|
+
fontWeight?: number | undefined;
|
|
939
|
+
}
|
|
940
|
+
autocomplete?: boolean | undefined;
|
|
941
|
+
autosave?: boolean | undefined;
|
|
942
|
+
};
|
|
1757
943
|
|
|
1758
|
-
type
|
|
1759
|
-
// type
|
|
1760
|
-
//
|
|
1761
|
-
//
|
|
1762
|
-
//
|
|
944
|
+
type RequiredSettings = RequiredDeep<Settings>;
|
|
945
|
+
// type RequiredSettings = {
|
|
946
|
+
// textEditor: {
|
|
947
|
+
// fontSize: number;
|
|
948
|
+
// fontColor: string;
|
|
949
|
+
// fontWeight: number;
|
|
950
|
+
// }
|
|
951
|
+
// autocomplete: boolean;
|
|
952
|
+
// autosave: boolean;
|
|
1763
953
|
// }
|
|
1764
954
|
```
|
|
1765
955
|
|
|
1766
|
-
|
|
956
|
+
Note that types containing overloaded functions are not made deeply required due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
957
|
+
|
|
958
|
+
@category Utilities
|
|
959
|
+
@category Object
|
|
960
|
+
@category Array
|
|
961
|
+
@category Set
|
|
962
|
+
@category Map
|
|
1767
963
|
*/
|
|
1768
|
-
type
|
|
964
|
+
type RequiredDeep<T, E extends ExcludeUndefined<T> = ExcludeUndefined<T>> = E extends BuiltIns ? E : E extends Map<infer KeyType, infer ValueType> ? Map<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends Set<infer ItemType> ? Set<RequiredDeep<ItemType>> : E extends ReadonlyMap<infer KeyType, infer ValueType> ? ReadonlyMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends ReadonlySet<infer ItemType> ? ReadonlySet<RequiredDeep<ItemType>> : E extends WeakMap<infer KeyType, infer ValueType> ? WeakMap<RequiredDeep<KeyType>, RequiredDeep<ValueType>> : E extends WeakSet<infer ItemType> ? WeakSet<RequiredDeep<ItemType>> : E extends Promise<infer ValueType> ? Promise<RequiredDeep<ValueType>> : E extends ((...arguments_: any[]) => unknown) ? {} extends RequiredObjectDeep<E> ? E : HasMultipleCallSignatures<E> extends true ? E : ((...arguments_: Parameters<E>) => ReturnType<E>) & RequiredObjectDeep<E> : E extends object ? E extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
965
|
+
? ItemType[] extends E // Test for arrays (non-tuples) specifically
|
|
966
|
+
? Array<RequiredDeep<ItemType>> // Recreate relevant array type to prevent eager evaluation of circular reference
|
|
967
|
+
: RequiredObjectDeep<E> // Tuples behave properly
|
|
968
|
+
: RequiredObjectDeep<E> : unknown;
|
|
969
|
+
type RequiredObjectDeep<ObjectType extends object> = { [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]> };
|
|
1769
970
|
//#endregion
|
|
1770
|
-
//#region
|
|
971
|
+
//#region ../../node_modules/type-fest/source/set-optional.d.ts
|
|
1771
972
|
/**
|
|
1772
973
|
Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
|
|
1773
974
|
|
|
@@ -1778,9 +979,9 @@ Use-case: You want to define a single model where the only thing that changes is
|
|
|
1778
979
|
import type {SetOptional} from 'type-fest';
|
|
1779
980
|
|
|
1780
981
|
type Foo = {
|
|
1781
|
-
a: number;
|
|
1782
|
-
b?: string;
|
|
1783
|
-
c: boolean;
|
|
982
|
+
a: number;
|
|
983
|
+
b?: string;
|
|
984
|
+
c: boolean;
|
|
1784
985
|
}
|
|
1785
986
|
|
|
1786
987
|
type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
@@ -1791,11 +992,16 @@ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
|
|
|
1791
992
|
// }
|
|
1792
993
|
```
|
|
1793
994
|
|
|
1794
|
-
@
|
|
995
|
+
@category Object
|
|
1795
996
|
*/
|
|
1796
|
-
type SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown
|
|
997
|
+
type SetOptional<BaseType, Keys extends keyof BaseType> = BaseType extends unknown // To distribute `BaseType` when it's a union type.
|
|
998
|
+
? Simplify<
|
|
999
|
+
// Pick just the keys that are readonly from the base type.
|
|
1000
|
+
Except<BaseType, Keys> &
|
|
1001
|
+
// Pick the keys that should be mutable from the base type and make them mutable.
|
|
1002
|
+
Partial<HomomorphicPick<BaseType, Keys>>> : never;
|
|
1797
1003
|
//#endregion
|
|
1798
|
-
//#region
|
|
1004
|
+
//#region ../../node_modules/type-fest/source/set-required.d.ts
|
|
1799
1005
|
/**
|
|
1800
1006
|
Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
|
|
1801
1007
|
|
|
@@ -1806,9 +1012,9 @@ Use-case: You want to define a single model where the only thing that changes is
|
|
|
1806
1012
|
import type {SetRequired} from 'type-fest';
|
|
1807
1013
|
|
|
1808
1014
|
type Foo = {
|
|
1809
|
-
a?: number;
|
|
1810
|
-
b: string;
|
|
1811
|
-
c?: boolean;
|
|
1015
|
+
a?: number;
|
|
1016
|
+
b: string;
|
|
1017
|
+
c?: boolean;
|
|
1812
1018
|
}
|
|
1813
1019
|
|
|
1814
1020
|
type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
|
|
@@ -1823,60 +1029,27 @@ type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
|
|
|
1823
1029
|
//=> [number, number, number?]
|
|
1824
1030
|
```
|
|
1825
1031
|
|
|
1826
|
-
@
|
|
1032
|
+
@category Object
|
|
1827
1033
|
*/
|
|
1828
|
-
type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<
|
|
1034
|
+
type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<
|
|
1035
|
+
// Pick just the keys that are optional from the base type.
|
|
1036
|
+
Except<BaseType, Keys> &
|
|
1037
|
+
// Pick the keys that should be required from the base type and make them required.
|
|
1038
|
+
Required<HomomorphicPick<BaseType, Keys>>>;
|
|
1829
1039
|
/**
|
|
1830
1040
|
Remove the optional modifier from the specified keys in an array.
|
|
1831
1041
|
*/
|
|
1832
|
-
type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
Note: This type can make readonly `Set` and `Map` writable. This behavior is different from `Readonly<T>` (as of TypeScript 5.2.2). See: https://github.com/microsoft/TypeScript/issues/29655
|
|
1845
|
-
|
|
1846
|
-
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
|
1847
|
-
|
|
1848
|
-
@example
|
|
1849
|
-
```
|
|
1850
|
-
import type {Writable} from 'type-fest';
|
|
1851
|
-
|
|
1852
|
-
type Foo = {
|
|
1853
|
-
readonly a: number;
|
|
1854
|
-
readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
|
|
1855
|
-
readonly c: boolean;
|
|
1856
|
-
};
|
|
1857
|
-
|
|
1858
|
-
const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
|
|
1859
|
-
writableFoo.a = 3;
|
|
1860
|
-
writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
|
|
1861
|
-
writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
|
1862
|
-
|
|
1863
|
-
type SomeWritable = Writable<Foo, 'b' | 'c'>;
|
|
1864
|
-
// type SomeWritable = {
|
|
1865
|
-
// readonly a: number;
|
|
1866
|
-
// b: readonly string[]; // It's now writable. The type of the property remains unaffected.
|
|
1867
|
-
// c: boolean; // It's now writable.
|
|
1868
|
-
// }
|
|
1869
|
-
|
|
1870
|
-
// Also supports array
|
|
1871
|
-
const readonlyArray: readonly number[] = [1, 2, 3];
|
|
1872
|
-
readonlyArray.push(4); // Will fail as the array itself is readonly.
|
|
1873
|
-
const writableArray: Writable<typeof readonlyArray> = readonlyArray as Writable<typeof readonlyArray>;
|
|
1874
|
-
writableArray.push(4); // Will work as the array itself is now writable.
|
|
1875
|
-
```
|
|
1876
|
-
|
|
1877
|
-
@group type-fest
|
|
1878
|
-
*/
|
|
1879
|
-
type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> = BaseType extends ReadonlyMap<infer KeyType, infer ValueType> ? Map<KeyType, ValueType> : BaseType extends ReadonlySet<infer ItemType> ? Set<ItemType> : BaseType extends readonly unknown[] ? WritableArray<BaseType> : Simplify<Except<BaseType, Keys> & { -readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType] }>;
|
|
1042
|
+
type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [], Accumulator extends UnknownArray = []> = TArray extends unknown // For distributing `TArray` when it's a union
|
|
1043
|
+
? keyof TArray & `${number}` extends never
|
|
1044
|
+
// Exit if `TArray` is empty (e.g., []), or
|
|
1045
|
+
// `TArray` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
|
|
1046
|
+
? [...Accumulator, ...TArray] : TArray extends readonly [(infer First)?, ...infer Rest] ? '0' extends OptionalKeysOf<TArray> // If the first element of `TArray` is optional
|
|
1047
|
+
? `${Counter['length']}` extends `${Keys & (string | number)}` // If the current index needs to be required
|
|
1048
|
+
? SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, First]>
|
|
1049
|
+
// If the current element is optional, but it doesn't need to be required,
|
|
1050
|
+
// then we can exit early, since no further elements can now be made required.
|
|
1051
|
+
: [...Accumulator, ...TArray] : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]> : never // Should never happen, since `[(infer F)?, ...infer R]` is a top-type for arrays.
|
|
1052
|
+
: never; // Should never happen
|
|
1880
1053
|
//#endregion
|
|
1881
1054
|
//#region src/types/options.d.ts
|
|
1882
1055
|
type StringUnionToFlexibleOptionArray<Op extends string> = Array<Op extends unknown ? FlexibleOption<Op> : never>;
|
|
@@ -2051,6 +1224,12 @@ interface CommonRuleAndGroupProperties {
|
|
|
2051
1224
|
path?: Path;
|
|
2052
1225
|
id?: string;
|
|
2053
1226
|
disabled?: boolean;
|
|
1227
|
+
/**
|
|
1228
|
+
* Whether this rule or group is muted. When muted, the rule or group
|
|
1229
|
+
* is excluded from query export formats (SQL, JSON, MongoDB, etc.).
|
|
1230
|
+
* For groups, muting recursively mutes all children.
|
|
1231
|
+
*/
|
|
1232
|
+
muted?: boolean;
|
|
2054
1233
|
}
|
|
2055
1234
|
/**
|
|
2056
1235
|
* The main rule type. The `field`, `operator`, and `value` properties
|
|
@@ -3035,6 +2214,14 @@ interface Classnames {
|
|
|
3035
2214
|
*/
|
|
3036
2215
|
lockGroup: Classname;
|
|
3037
2216
|
/**
|
|
2217
|
+
* Classnames applied to the `<button>` to mute a Rule.
|
|
2218
|
+
*/
|
|
2219
|
+
muteRule: Classname;
|
|
2220
|
+
/**
|
|
2221
|
+
* Classnames applied to the `<button>` to mute a RuleGroup.
|
|
2222
|
+
*/
|
|
2223
|
+
muteGroup: Classname;
|
|
2224
|
+
/**
|
|
3038
2225
|
* Classnames applied to the `<select>` control for value sources.
|
|
3039
2226
|
*/
|
|
3040
2227
|
valueSource: Classname;
|
|
@@ -3086,6 +2273,10 @@ interface Classnames {
|
|
|
3086
2273
|
*/
|
|
3087
2274
|
disabled: Classname;
|
|
3088
2275
|
/**
|
|
2276
|
+
* Classname(s) applied to muted elements.
|
|
2277
|
+
*/
|
|
2278
|
+
muted: Classname;
|
|
2279
|
+
/**
|
|
3089
2280
|
* Classname(s) applied to each element in a series of value editors.
|
|
3090
2281
|
*/
|
|
3091
2282
|
valueListItem: Classname;
|
|
@@ -3099,6 +2290,89 @@ interface Classnames {
|
|
|
3099
2290
|
hasSubQuery: Classname;
|
|
3100
2291
|
}
|
|
3101
2292
|
/**
|
|
2293
|
+
* Placeholder strings for option lists.
|
|
2294
|
+
*
|
|
2295
|
+
* @group Props
|
|
2296
|
+
*/
|
|
2297
|
+
interface Placeholder {
|
|
2298
|
+
/**
|
|
2299
|
+
* Value for the placeholder field option if autoSelectField is false,
|
|
2300
|
+
* or the placeholder operator option if autoSelectOperator is false.
|
|
2301
|
+
*/
|
|
2302
|
+
placeholderName?: string;
|
|
2303
|
+
/**
|
|
2304
|
+
* Label for the placeholder field option if autoSelectField is false,
|
|
2305
|
+
* or the placeholder operator option if autoSelectOperator is false.
|
|
2306
|
+
*/
|
|
2307
|
+
placeholderLabel?: string;
|
|
2308
|
+
/**
|
|
2309
|
+
* Label for the placeholder field optgroup if autoSelectField is false,
|
|
2310
|
+
* or the placeholder operator optgroup if autoSelectOperator is false.
|
|
2311
|
+
*/
|
|
2312
|
+
placeholderGroupLabel?: string;
|
|
2313
|
+
}
|
|
2314
|
+
/**
|
|
2315
|
+
* A translation for a component with `title` only.
|
|
2316
|
+
*
|
|
2317
|
+
* @group Props
|
|
2318
|
+
*/
|
|
2319
|
+
interface BaseTranslation {
|
|
2320
|
+
title?: string;
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* A translation for a component with `title` and `label`.
|
|
2324
|
+
*
|
|
2325
|
+
* @group Props
|
|
2326
|
+
*/
|
|
2327
|
+
interface BaseTranslationWithLabel<LabelType = string> extends BaseTranslation {
|
|
2328
|
+
label?: LabelType;
|
|
2329
|
+
}
|
|
2330
|
+
/**
|
|
2331
|
+
* A translation for a component with `title` and a placeholder.
|
|
2332
|
+
*
|
|
2333
|
+
* @group Props
|
|
2334
|
+
*/
|
|
2335
|
+
interface BaseTranslationWithPlaceholders extends BaseTranslation, Placeholder {}
|
|
2336
|
+
/**
|
|
2337
|
+
* The shape of the `translations` prop.
|
|
2338
|
+
*
|
|
2339
|
+
* @group Props
|
|
2340
|
+
*/
|
|
2341
|
+
interface BaseTranslations<LabelType = string> {
|
|
2342
|
+
fields: BaseTranslationWithPlaceholders;
|
|
2343
|
+
operators: BaseTranslationWithPlaceholders;
|
|
2344
|
+
values: BaseTranslationWithPlaceholders;
|
|
2345
|
+
matchMode: BaseTranslation;
|
|
2346
|
+
matchThreshold: BaseTranslation;
|
|
2347
|
+
value: BaseTranslation;
|
|
2348
|
+
removeRule: BaseTranslationWithLabel<LabelType>;
|
|
2349
|
+
removeGroup: BaseTranslationWithLabel<LabelType>;
|
|
2350
|
+
addRule: BaseTranslationWithLabel<LabelType>;
|
|
2351
|
+
addGroup: BaseTranslationWithLabel<LabelType>;
|
|
2352
|
+
combinators: BaseTranslation;
|
|
2353
|
+
notToggle: BaseTranslationWithLabel<LabelType>;
|
|
2354
|
+
cloneRule: BaseTranslationWithLabel<LabelType>;
|
|
2355
|
+
cloneRuleGroup: BaseTranslationWithLabel<LabelType>;
|
|
2356
|
+
shiftActionUp: BaseTranslationWithLabel<LabelType>;
|
|
2357
|
+
shiftActionDown: BaseTranslationWithLabel<LabelType>;
|
|
2358
|
+
dragHandle: BaseTranslationWithLabel<LabelType>;
|
|
2359
|
+
lockRule: BaseTranslationWithLabel<LabelType>;
|
|
2360
|
+
lockGroup: BaseTranslationWithLabel<LabelType>;
|
|
2361
|
+
lockRuleDisabled: BaseTranslationWithLabel<LabelType>;
|
|
2362
|
+
lockGroupDisabled: BaseTranslationWithLabel<LabelType>;
|
|
2363
|
+
muteRule: BaseTranslationWithLabel<LabelType>;
|
|
2364
|
+
muteGroup: BaseTranslationWithLabel<LabelType>;
|
|
2365
|
+
unmuteRule: BaseTranslationWithLabel<LabelType>;
|
|
2366
|
+
unmuteGroup: BaseTranslationWithLabel<LabelType>;
|
|
2367
|
+
valueSourceSelector: BaseTranslation;
|
|
2368
|
+
}
|
|
2369
|
+
/**
|
|
2370
|
+
* The full `translations` interface with all properties required.
|
|
2371
|
+
*
|
|
2372
|
+
* @group Props
|
|
2373
|
+
*/
|
|
2374
|
+
type BaseTranslationsFull<LabelType = string> = RequiredDeep<BaseTranslations<LabelType>>;
|
|
2375
|
+
/**
|
|
3102
2376
|
* Functions included in the `actions` prop passed to every subcomponent.
|
|
3103
2377
|
*
|
|
3104
2378
|
* @group Props
|
|
@@ -3177,6 +2451,12 @@ declare const defaultPlaceholderValueLabel: typeof defaultPlaceholderLabel;
|
|
|
3177
2451
|
*/
|
|
3178
2452
|
declare const defaultPlaceholderValueGroupLabel: typeof defaultPlaceholderLabel;
|
|
3179
2453
|
/**
|
|
2454
|
+
* Default configuration of translatable strings.
|
|
2455
|
+
*
|
|
2456
|
+
* @group Defaults
|
|
2457
|
+
*/
|
|
2458
|
+
declare const defaultTranslations: BaseTranslationsFull;
|
|
2459
|
+
/**
|
|
3180
2460
|
* Default character used to `.join` and `.split` arrays.
|
|
3181
2461
|
*
|
|
3182
2462
|
* @group Defaults
|
|
@@ -3253,8 +2533,11 @@ declare const standardClassnames: {
|
|
|
3253
2533
|
readonly dndDropNotAllowed: "dndDropNotAllowed";
|
|
3254
2534
|
readonly dragHandle: "queryBuilder-dragHandle";
|
|
3255
2535
|
readonly disabled: "queryBuilder-disabled";
|
|
2536
|
+
readonly muted: "queryBuilder-muted";
|
|
3256
2537
|
readonly lockRule: "rule-lock";
|
|
3257
2538
|
readonly lockGroup: "ruleGroup-lock";
|
|
2539
|
+
readonly muteRule: "rule-mute";
|
|
2540
|
+
readonly muteGroup: "ruleGroup-mute";
|
|
3258
2541
|
readonly valueSource: "rule-valueSource";
|
|
3259
2542
|
readonly valueListItem: "rule-value-list-item";
|
|
3260
2543
|
readonly branches: "queryBuilder-branches";
|
|
@@ -3301,6 +2584,8 @@ declare const TestID: {
|
|
|
3301
2584
|
readonly dragHandle: "drag-handle";
|
|
3302
2585
|
readonly lockRule: "lock-rule";
|
|
3303
2586
|
readonly lockGroup: "lock-group";
|
|
2587
|
+
readonly muteRule: "mute-rule";
|
|
2588
|
+
readonly muteGroup: "mute-group";
|
|
3304
2589
|
readonly valueSourceSelector: "value-source-selector";
|
|
3305
2590
|
readonly matchModeEditor: "match-mode-editor";
|
|
3306
2591
|
};
|
|
@@ -4183,10 +3468,18 @@ declare const isRuleGroupTypeIC: (rg: unknown) => rg is RuleGroupTypeIC;
|
|
|
4183
3468
|
declare const isValidationResult: (vr?: ValidationResult) => vr is ValidationResult;
|
|
4184
3469
|
/**
|
|
4185
3470
|
* Determines if a rule or group is valid based on a validation result (if defined)
|
|
4186
|
-
* or a validator function. Returns `true` if neither are defined
|
|
3471
|
+
* or a validator function. Returns `true` if neither are defined and the `muted`
|
|
3472
|
+
* property is not `true`.
|
|
4187
3473
|
*/
|
|
4188
3474
|
declare const isRuleOrGroupValid: (rg: RuleType | RuleGroupTypeAny, validationResult?: boolean | ValidationResult, validator?: RuleValidator) => boolean;
|
|
4189
3475
|
//#endregion
|
|
3476
|
+
//#region src/utils/mergeAnyTranslations.d.ts
|
|
3477
|
+
/**
|
|
3478
|
+
* Merges any number of partial translations into a single definition.
|
|
3479
|
+
*/
|
|
3480
|
+
declare const mergeAnyTranslations: (base: Record<string, Record<string, unknown>>, ...otherTranslations: (Record<string, Record<string, unknown>> | undefined)[]) => Record<string, Record<string, unknown>>;
|
|
3481
|
+
declare const mergeAnyTranslation: (el: string, keyPropContextMap: Record<string, [unknown, unknown]>, defaults?: Record<string, Record<string, unknown>>) => Record<string, Record<string, unknown>> | undefined;
|
|
3482
|
+
//#endregion
|
|
4190
3483
|
//#region src/utils/mergeClassnames.d.ts
|
|
4191
3484
|
type MergeClassnamesParams = (Partial<Classnames> | undefined)[];
|
|
4192
3485
|
/**
|
|
@@ -4354,6 +3647,19 @@ declare const uniqOptGroups: <T extends BaseOption>(originalArray: FlexibleOptio
|
|
|
4354
3647
|
* @group Option Lists
|
|
4355
3648
|
*/
|
|
4356
3649
|
declare const uniqOptList: <T extends BaseOption>(originalArray: FlexibleOptionList<T>) => WithUnknownIndex<BaseOption & FullOption>[] | OptionGroup<ToFullOption<T>>[];
|
|
3650
|
+
interface PreparedOptionList<O extends FullOption> {
|
|
3651
|
+
defaultOption: FullOption;
|
|
3652
|
+
optionList: O[] | OptionGroup<O>[];
|
|
3653
|
+
optionsMap: Partial<FullOptionRecord<FullOption>>;
|
|
3654
|
+
}
|
|
3655
|
+
interface PrepareOptionListParams<O extends FullOption> {
|
|
3656
|
+
placeholder?: Placeholder;
|
|
3657
|
+
optionList?: FlexibleOptionListProp<O> | BaseOptionMap<O>;
|
|
3658
|
+
baseOption?: Record<string, unknown>;
|
|
3659
|
+
labelMap?: Record<string, string>;
|
|
3660
|
+
autoSelectOption?: boolean;
|
|
3661
|
+
}
|
|
3662
|
+
declare const prepareOptionList: <O extends FullOption>(props: PrepareOptionListParams<O>) => PreparedOptionList<O>;
|
|
4357
3663
|
//#endregion
|
|
4358
3664
|
//#region src/utils/parseNumber.d.ts
|
|
4359
3665
|
/**
|
|
@@ -4793,5 +4099,5 @@ declare function transformQuery(query: RuleGroupType, options?: TransformQueryOp
|
|
|
4793
4099
|
*/
|
|
4794
4100
|
declare function transformQuery(query: RuleGroupTypeIC, options?: TransformQueryOptions<RuleGroupTypeIC>): any;
|
|
4795
4101
|
//#endregion
|
|
4796
|
-
export { AccessibleDescriptionGenerator, ActionElementEventHandler, AddOptions,
|
|
4102
|
+
export { AccessibleDescriptionGenerator, ActionElementEventHandler, AddOptions, Arity, BaseFullOption, BaseOption, BaseOptionMap, BaseTranslation, BaseTranslationWithLabel, BaseTranslationWithPlaceholders, BaseTranslations, BaseTranslationsFull, Classname, Classnames, Combinator, CombinatorByValue, CommonRuleAndGroupProperties, CommonRuleSubComponentProps, ConstituentWordOrder, ConstituentWordOrderString, DefaultCombinator, DefaultCombinatorExtended, DefaultCombinatorName, DefaultCombinatorNameExtended, DefaultCombinators, DefaultCombinatorsExtended, DefaultMatchModes, DefaultOperator, DefaultOperatorName, DefaultOperators, DefaultRuleGroupArray, DefaultRuleGroupICArray, DefaultRuleGroupType, DefaultRuleGroupTypeAny, DefaultRuleGroupTypeIC, DefaultRuleOrGroupArray, DefaultRuleType, DndDropTargetType, DragCollection, DraggedItem, DropCollection, DropEffect, DropResult, ExportFormat, ExportObjectFormats, ExportOperatorMap, Field, FieldByValue, FindPathReturnType, FlexibleOption, FlexibleOptionGroup, FlexibleOptionList, FlexibleOptionListProp, FormatQueryFinalOptions, FormatQueryOptions, FormatQueryValidateRule, FullCombinator, FullField, FullOperator, FullOption, FullOptionList, FullOptionMap, FullOptionRecord, GenericizeRuleGroupType, GetOptionIdentifierType, GetOptionType, GetRuleGroupType, GetRuleTypeFromGroupWithFieldAndOperator, GroupOptions, GroupVariantCondition, InputType, InsertOptions, type JsonLogicAll, type JsonLogicAnd, type JsonLogicDoubleNegation, type JsonLogicEqual, type JsonLogicGreaterThan, type JsonLogicGreaterThanOrEqual, type JsonLogicInArray, type JsonLogicInString, type JsonLogicLessThan, type JsonLogicLessThanOrEqual, type JsonLogicNegation, type JsonLogicNone, type JsonLogicNotEqual, type JsonLogicOr, type JsonLogicReservedOperations, type JsonLogicRulesLogic, type JsonLogicSome, type JsonLogicStrictEqual, type JsonLogicStrictNotEqual, type JsonLogicVar, LogType, MatchConfig, MatchMode, MatchModeOptions, MoveOptions, NLTranslationKey, NLTranslations, NameLabelPair, Operator, OperatorByValue, Option, OptionGroup, OptionList, ParameterizedNamedSQL, ParameterizedSQL, ParseNumberMethod, ParseNumberOptions, ParseNumbersPropConfig, Path, Placeholder, PrepareOptionListParams, PreparedOptionList, PreparerOptions, QueryActions, QueryValidator, RQBJsonLogic, RQBJsonLogicEndsWith, RQBJsonLogicStartsWith, RQBJsonLogicVar, RegenerateIdOptions, RemoveNullability, RuleGroupArray, RuleGroupICArray, RuleGroupProcessor, RuleGroupType, RuleGroupTypeAny, RuleGroupTypeIC, RuleOrGroupArray, RuleProcessor, RuleType, RuleValidator, SQLPreset, StringUnionToFlexibleOptionArray, StringUnionToFullOptionArray, TestID, ToFlexibleOption, ToFullOption, TransformQueryOptions, UpdateOptions, UpdateableProperties, ValidationMap, ValidationResult, ValueChangeEventHandler, ValueEditorType, ValueOption, ValueProcessor, ValueProcessorByRule, ValueProcessorLegacy, ValueProcessorOptions, ValueSource, ValueSourceFlexibleOptions, ValueSourceFullOptions, ValueSources, WithRequired, WithUnknownIndex, add, bigIntJsonParseReviver, bigIntJsonStringifyReplacer, celCombinatorMap, clsx, convertFromIC, convertQuery, convertToIC, defaultCELValueProcessor, defaultCombinatorLabelMap, defaultCombinators, defaultCombinatorsExtended, defaultControlClassnames, defaultExportOperatorMap, defaultJoinChar, defaultMatchModes, defaultMongoDBValueProcessor, defaultNLTranslations, defaultOperatorLabelMap, defaultOperatorNegationMap, defaultOperatorProcessorNL, defaultOperatorProcessorSQL, defaultOperators, defaultPlaceholderFieldGroupLabel, defaultPlaceholderFieldLabel, defaultPlaceholderFieldName, defaultPlaceholderLabel, defaultPlaceholderName, defaultPlaceholderOperatorGroupLabel, defaultPlaceholderOperatorLabel, defaultPlaceholderOperatorName, defaultPlaceholderValueGroupLabel, defaultPlaceholderValueLabel, defaultPlaceholderValueName, defaultRuleGroupProcessorCEL, defaultRuleGroupProcessorDrizzle, defaultRuleGroupProcessorElasticSearch, defaultRuleGroupProcessorJSONata, defaultRuleGroupProcessorJsonLogic, defaultRuleGroupProcessorLDAP, defaultRuleGroupProcessorMongoDB, defaultRuleGroupProcessorMongoDBQuery, defaultRuleGroupProcessorNL, defaultRuleGroupProcessorParameterized, defaultRuleGroupProcessorPrisma, defaultRuleGroupProcessorSQL, defaultRuleGroupProcessorSequelize, defaultRuleGroupProcessorSpEL, defaultRuleProcessorCEL, defaultRuleProcessorDrizzle, defaultRuleProcessorElasticSearch, defaultRuleProcessorJSONata, defaultRuleProcessorJsonLogic, defaultRuleProcessorLDAP, defaultRuleProcessorMongoDB, defaultRuleProcessorMongoDBQuery, defaultRuleProcessorNL, defaultRuleProcessorParameterized, defaultRuleProcessorPrisma, defaultRuleProcessorSQL, defaultRuleProcessorSequelize, defaultRuleProcessorSpEL, defaultSpELValueProcessor, defaultTranslations, defaultValidator, defaultValueProcessor, defaultValueProcessorByRule, defaultValueProcessorCELByRule, defaultValueProcessorMongoDBByRule, defaultValueProcessorNL, defaultValueProcessorSpELByRule, filterFieldsByComparator, findID, findPath, formatQuery, formatQueryOptionPresets, generateAccessibleDescription, generateID, getCommonAncestorPath, getFirstOption, getMatchModesUtil, getNLTranslataion, getOption, getParentPath, getParseNumberMethod, getPathOfID, getQuoteFieldNamesWithArray, getQuotedFieldName, getValidationClassNames, getValueSourcesUtil, group, groupInvalidReasons, insert, isAncestor, isFlexibleOptionArray, isFlexibleOptionGroupArray, isFullOptionArray, isFullOptionGroupArray, isOptionGroupArray, isPojo, isRuleGroup, isRuleGroupType, isRuleGroupTypeIC, isRuleOrGroupValid, isRuleType, isValidValue, isValidationResult, isValueProcessorLegacy, joinWith, jsonLogicAdditionalOperators, lc, mapSQLOperator, mergeAnyTranslation, mergeAnyTranslations, mergeClassnames, mongoDbFallback, mongoOperators, move, normalizeConstituentWordOrder, nullFreeArray, nullOrUndefinedOrEmpty, numericRegex, numerifyValues, objectEntries, objectKeys, parseNumber, pathIsDisabled, pathsAreEqual, prepareOptionList, prepareRule, prepareRuleGroup, prepareRuleOrGroup, prismaFallback, prismaOperators, processMatchMode, regenerateID, regenerateIDs, remove, rootPath, shouldRenderAsNumber, splitBy, sqlDialectPresets, standardClassnames, toArray, toFlatOptionArray, toFullOption, toFullOptionList, toFullOptionMap, transformQuery, trimIfString, uniqByIdentifier, uniqByName, uniqOptGroups, uniqOptList, update };
|
|
4797
4103
|
//# sourceMappingURL=react-querybuilder_core.cjs.development.d.ts.map
|