@esposter/shared 2.17.0 → 2.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +23 -23
- package/dist/index.d.ts +102 -83
- package/dist/index.js +168 -167
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ declare class NotInitializedError<T$1 extends string = string> extends Error {
|
|
|
29
29
|
//#region src/models/router/RoutePath.d.ts
|
|
30
30
|
declare const RoutePath: {
|
|
31
31
|
readonly About: "/about";
|
|
32
|
+
readonly Achievements: "/achievements";
|
|
32
33
|
readonly Anime: "/anime";
|
|
33
34
|
readonly Calendar: "/calendar";
|
|
34
35
|
readonly Clicker: "/clicker";
|
|
@@ -57,7 +58,7 @@ declare const RoutePath: {
|
|
|
57
58
|
};
|
|
58
59
|
type RoutePath = typeof RoutePath;
|
|
59
60
|
//#endregion
|
|
60
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
61
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/primitive.d.ts
|
|
61
62
|
/**
|
|
62
63
|
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
63
64
|
|
|
@@ -65,7 +66,7 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
65
66
|
*/
|
|
66
67
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
67
68
|
//#endregion
|
|
68
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
69
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/basic.d.ts
|
|
69
70
|
/**
|
|
70
71
|
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
71
72
|
|
|
@@ -76,7 +77,7 @@ type Class<T$1, Arguments extends unknown[] = any[]> = {
|
|
|
76
77
|
new (...arguments_: Arguments): T$1;
|
|
77
78
|
};
|
|
78
79
|
//#endregion
|
|
79
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
80
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-any.d.ts
|
|
80
81
|
/**
|
|
81
82
|
Returns a boolean for whether the given type is `any`.
|
|
82
83
|
|
|
@@ -91,8 +92,8 @@ import type {IsAny} from 'type-fest';
|
|
|
91
92
|
const typedObject = {a: 1, b: 2} as const;
|
|
92
93
|
const anyObject: any = {a: 1, b: 2};
|
|
93
94
|
|
|
94
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(
|
|
95
|
-
return
|
|
95
|
+
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(object: O, key: K) {
|
|
96
|
+
return object[key];
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
const typedA = get(typedObject, 'a');
|
|
@@ -107,7 +108,7 @@ const anyA = get(anyObject, 'a');
|
|
|
107
108
|
*/
|
|
108
109
|
type IsAny<T$1> = 0 extends 1 & NoInfer<T$1> ? true : false;
|
|
109
110
|
//#endregion
|
|
110
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
111
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-optional-key-of.d.ts
|
|
111
112
|
/**
|
|
112
113
|
Returns a boolean for whether the given key is an optional key of type.
|
|
113
114
|
|
|
@@ -117,17 +118,17 @@ This is useful when writing utility types or schema validators that need to diff
|
|
|
117
118
|
```
|
|
118
119
|
import type {IsOptionalKeyOf} from 'type-fest';
|
|
119
120
|
|
|
120
|
-
|
|
121
|
+
type User = {
|
|
121
122
|
name: string;
|
|
122
123
|
surname: string;
|
|
123
124
|
|
|
124
125
|
luckyNumber?: number;
|
|
125
|
-
}
|
|
126
|
+
};
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
type Admin = {
|
|
128
129
|
name: string;
|
|
129
130
|
surname?: string;
|
|
130
|
-
}
|
|
131
|
+
};
|
|
131
132
|
|
|
132
133
|
type T1 = IsOptionalKeyOf<User, 'luckyNumber'>;
|
|
133
134
|
//=> true
|
|
@@ -150,7 +151,7 @@ type T5 = IsOptionalKeyOf<User | Admin, 'surname'>;
|
|
|
150
151
|
*/
|
|
151
152
|
type IsOptionalKeyOf<Type extends object, Key$1 extends keyof Type> = IsAny<Type | Key$1> extends true ? never : Key$1 extends keyof Type ? Type extends Record<Key$1, Type[Key$1]> ? false : true : false;
|
|
152
153
|
//#endregion
|
|
153
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
154
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/optional-keys-of.d.ts
|
|
154
155
|
/**
|
|
155
156
|
Extract all optional keys from the given type.
|
|
156
157
|
|
|
@@ -160,12 +161,12 @@ This is useful when you want to create a new type that contains different type v
|
|
|
160
161
|
```
|
|
161
162
|
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
type User = {
|
|
164
165
|
name: string;
|
|
165
166
|
surname: string;
|
|
166
167
|
|
|
167
168
|
luckyNumber?: number;
|
|
168
|
-
}
|
|
169
|
+
};
|
|
169
170
|
|
|
170
171
|
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
171
172
|
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
@@ -173,12 +174,12 @@ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKe
|
|
|
173
174
|
};
|
|
174
175
|
|
|
175
176
|
const update1: UpdateOperation<User> = {
|
|
176
|
-
name: 'Alice'
|
|
177
|
+
name: 'Alice',
|
|
177
178
|
};
|
|
178
179
|
|
|
179
180
|
const update2: UpdateOperation<User> = {
|
|
180
181
|
name: 'Bob',
|
|
181
|
-
luckyNumber: REMOVE_FIELD
|
|
182
|
+
luckyNumber: REMOVE_FIELD,
|
|
182
183
|
};
|
|
183
184
|
```
|
|
184
185
|
|
|
@@ -188,7 +189,7 @@ type OptionalKeysOf<Type extends object> = Type extends unknown // For distribut
|
|
|
188
189
|
? (keyof { [Key in keyof Type as IsOptionalKeyOf<Type, Key> extends false ? never : Key]: never }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
|
|
189
190
|
: never;
|
|
190
191
|
//#endregion
|
|
191
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
192
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-keys-of.d.ts
|
|
192
193
|
/**
|
|
193
194
|
Extract all required keys from the given type.
|
|
194
195
|
|
|
@@ -198,17 +199,23 @@ This is useful when you want to create a new type that contains different type v
|
|
|
198
199
|
```
|
|
199
200
|
import type {RequiredKeysOf} from 'type-fest';
|
|
200
201
|
|
|
201
|
-
declare function createValidation<
|
|
202
|
+
declare function createValidation<
|
|
203
|
+
Entity extends object,
|
|
204
|
+
Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>,
|
|
205
|
+
>(field: Key, validator: (value: Entity[Key]) => boolean): (entity: Entity) => boolean;
|
|
202
206
|
|
|
203
|
-
|
|
207
|
+
type User = {
|
|
204
208
|
name: string;
|
|
205
209
|
surname: string;
|
|
206
|
-
|
|
207
210
|
luckyNumber?: number;
|
|
208
|
-
}
|
|
211
|
+
};
|
|
209
212
|
|
|
210
213
|
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
211
214
|
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
215
|
+
|
|
216
|
+
// @ts-expect-error
|
|
217
|
+
const validator3 = createValidation<User>('luckyNumber', value => value > 0);
|
|
218
|
+
// Error: Argument of type '"luckyNumber"' is not assignable to parameter of type '"name" | "surname"'.
|
|
212
219
|
```
|
|
213
220
|
|
|
214
221
|
@category Utilities
|
|
@@ -216,7 +223,7 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
|
|
|
216
223
|
type RequiredKeysOf<Type extends object> = Type extends unknown // For distributing `Type`
|
|
217
224
|
? Exclude<keyof Type, OptionalKeysOf<Type>> : never;
|
|
218
225
|
//#endregion
|
|
219
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
226
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-never.d.ts
|
|
220
227
|
/**
|
|
221
228
|
Returns a boolean for whether the given type is `never`.
|
|
222
229
|
|
|
@@ -230,29 +237,41 @@ Useful in type utilities, such as checking if something does not occur.
|
|
|
230
237
|
```
|
|
231
238
|
import type {IsNever, And} from 'type-fest';
|
|
232
239
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
And<
|
|
236
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
237
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
238
|
-
>;
|
|
239
|
-
|
|
240
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
241
|
-
AreStringsEqual<I, O> extends true
|
|
242
|
-
? never
|
|
243
|
-
: void;
|
|
244
|
-
|
|
245
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
246
|
-
if (input === output) {
|
|
247
|
-
process.exit(0);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
240
|
+
type A = IsNever<never>;
|
|
241
|
+
//=> true
|
|
250
242
|
|
|
251
|
-
|
|
252
|
-
//=>
|
|
243
|
+
type B = IsNever<any>;
|
|
244
|
+
//=> false
|
|
245
|
+
|
|
246
|
+
type C = IsNever<unknown>;
|
|
247
|
+
//=> false
|
|
248
|
+
|
|
249
|
+
type D = IsNever<never[]>;
|
|
250
|
+
//=> false
|
|
253
251
|
|
|
254
|
-
|
|
255
|
-
//=>
|
|
252
|
+
type E = IsNever<object>;
|
|
253
|
+
//=> false
|
|
254
|
+
|
|
255
|
+
type F = IsNever<string>;
|
|
256
|
+
//=> false
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
@example
|
|
260
|
+
```
|
|
261
|
+
import type {IsNever} from 'type-fest';
|
|
262
|
+
|
|
263
|
+
type IsTrue<T> = T extends true ? true : false;
|
|
264
|
+
|
|
265
|
+
// When a distributive conditional is instantiated with `never`, the entire conditional results in `never`.
|
|
266
|
+
type A = IsTrue<never>;
|
|
267
|
+
// ^? type A = never
|
|
268
|
+
|
|
269
|
+
// If you don't want that behaviour, you can explicitly add an `IsNever` check before the distributive conditional.
|
|
270
|
+
type IsTrueFixed<T> =
|
|
271
|
+
IsNever<T> extends true ? false : T extends true ? true : false;
|
|
272
|
+
|
|
273
|
+
type B = IsTrueFixed<never>;
|
|
274
|
+
// ^? type B = false
|
|
256
275
|
```
|
|
257
276
|
|
|
258
277
|
@category Type Guard
|
|
@@ -260,7 +279,7 @@ endIfEqual('abc', '123');
|
|
|
260
279
|
*/
|
|
261
280
|
type IsNever<T$1> = [T$1] extends [never] ? true : false;
|
|
262
281
|
//#endregion
|
|
263
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
282
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/if.d.ts
|
|
264
283
|
/**
|
|
265
284
|
An if-else-like type that resolves depending on whether the given `boolean` type is `true` or `false`.
|
|
266
285
|
|
|
@@ -273,7 +292,7 @@ Note:
|
|
|
273
292
|
|
|
274
293
|
@example
|
|
275
294
|
```
|
|
276
|
-
import {If} from 'type-fest';
|
|
295
|
+
import type {If} from 'type-fest';
|
|
277
296
|
|
|
278
297
|
type A = If<true, 'yes', 'no'>;
|
|
279
298
|
//=> 'yes'
|
|
@@ -293,7 +312,7 @@ type E = If<never, 'yes', 'no'>;
|
|
|
293
312
|
|
|
294
313
|
@example
|
|
295
314
|
```
|
|
296
|
-
import {If, IsAny, IsNever} from 'type-fest';
|
|
315
|
+
import type {If, IsAny, IsNever} from 'type-fest';
|
|
297
316
|
|
|
298
317
|
type A = If<IsAny<unknown>, 'is any', 'not any'>;
|
|
299
318
|
//=> 'not any'
|
|
@@ -304,7 +323,7 @@ type B = If<IsNever<never>, 'is never', 'not never'>;
|
|
|
304
323
|
|
|
305
324
|
@example
|
|
306
325
|
```
|
|
307
|
-
import {If, IsEqual} from 'type-fest';
|
|
326
|
+
import type {If, IsEqual} from 'type-fest';
|
|
308
327
|
|
|
309
328
|
type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
|
|
310
329
|
|
|
@@ -355,7 +374,7 @@ type Works = IncludesWithoutIf<HundredZeroes, '1'>;
|
|
|
355
374
|
*/
|
|
356
375
|
type If<Type extends boolean, IfBranch, ElseBranch> = IsNever<Type> extends true ? ElseBranch : Type extends true ? IfBranch : ElseBranch;
|
|
357
376
|
//#endregion
|
|
358
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
377
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/type.d.ts
|
|
359
378
|
/**
|
|
360
379
|
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
361
380
|
*/
|
|
@@ -373,7 +392,7 @@ type HasMultipleCallSignatures<T$1 extends (...arguments_: any[]) => unknown> =
|
|
|
373
392
|
(...arguments_: infer B): unknown;
|
|
374
393
|
} ? B extends A ? A extends B ? false : true : true : false;
|
|
375
394
|
//#endregion
|
|
376
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
395
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/simplify.d.ts
|
|
377
396
|
/**
|
|
378
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.
|
|
379
398
|
|
|
@@ -419,10 +438,11 @@ const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
|
419
438
|
const someType: SomeType = literal;
|
|
420
439
|
const someInterface: SomeInterface = literal;
|
|
421
440
|
|
|
422
|
-
function fn(object: Record<string, unknown>): void
|
|
441
|
+
declare function fn(object: Record<string, unknown>): void;
|
|
423
442
|
|
|
424
443
|
fn(literal); // Good: literal object type is sealed
|
|
425
444
|
fn(someType); // Good: type is sealed
|
|
445
|
+
// @ts-expect-error
|
|
426
446
|
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
427
447
|
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
428
448
|
```
|
|
@@ -433,7 +453,7 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
|
|
|
433
453
|
*/
|
|
434
454
|
type Simplify<T$1> = { [KeyType in keyof T$1]: T$1[KeyType] } & {};
|
|
435
455
|
//#endregion
|
|
436
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
456
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/is-equal.d.ts
|
|
437
457
|
/**
|
|
438
458
|
Returns a boolean for whether the two given types are equal.
|
|
439
459
|
|
|
@@ -460,11 +480,11 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
460
480
|
@category Type Guard
|
|
461
481
|
@category Utilities
|
|
462
482
|
*/
|
|
463
|
-
type IsEqual<A
|
|
483
|
+
type IsEqual<A, B> = [A] extends [B] ? [B] extends [A] ? _IsEqual<A, B> : false : false;
|
|
464
484
|
// This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
|
|
465
|
-
type _IsEqual<A
|
|
485
|
+
type _IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
|
|
466
486
|
//#endregion
|
|
467
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
487
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/omit-index-signature.d.ts
|
|
468
488
|
/**
|
|
469
489
|
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
470
490
|
|
|
@@ -482,6 +502,7 @@ It relies on the fact that an empty object (`{}`) is assignable to an object wit
|
|
|
482
502
|
```
|
|
483
503
|
const indexed: Record<string, unknown> = {}; // Allowed
|
|
484
504
|
|
|
505
|
+
// @ts-expect-error
|
|
485
506
|
const keyed: Record<'foo', unknown> = {}; // Error
|
|
486
507
|
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
487
508
|
```
|
|
@@ -495,16 +516,14 @@ type Indexed = {} extends Record<string, unknown>
|
|
|
495
516
|
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
496
517
|
|
|
497
518
|
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
498
|
-
?
|
|
499
|
-
:
|
|
519
|
+
? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
|
|
520
|
+
: '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
|
|
500
521
|
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
501
522
|
```
|
|
502
523
|
|
|
503
524
|
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
504
525
|
|
|
505
526
|
```
|
|
506
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
507
|
-
|
|
508
527
|
type OmitIndexSignature<ObjectType> = {
|
|
509
528
|
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
510
529
|
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
@@ -514,14 +533,12 @@ type OmitIndexSignature<ObjectType> = {
|
|
|
514
533
|
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
515
534
|
|
|
516
535
|
```
|
|
517
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
518
|
-
|
|
519
536
|
type OmitIndexSignature<ObjectType> = {
|
|
520
537
|
[KeyType in keyof ObjectType
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
538
|
+
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
539
|
+
as {} extends Record<KeyType, unknown>
|
|
540
|
+
? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
541
|
+
: KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
525
542
|
]: ObjectType[KeyType];
|
|
526
543
|
};
|
|
527
544
|
```
|
|
@@ -532,21 +549,21 @@ If `{}` is assignable, it means that `KeyType` is an index signature and we want
|
|
|
532
549
|
```
|
|
533
550
|
import type {OmitIndexSignature} from 'type-fest';
|
|
534
551
|
|
|
535
|
-
|
|
552
|
+
type Example = {
|
|
536
553
|
// These index signatures will be removed.
|
|
537
|
-
[x: string]: any
|
|
538
|
-
[x: number]: any
|
|
539
|
-
[x: symbol]: any
|
|
540
|
-
[x: `head-${string}`]: string
|
|
541
|
-
[x: `${string}-tail`]: string
|
|
542
|
-
[x: `head-${string}-tail`]: string
|
|
543
|
-
[x: `${bigint}`]: string
|
|
544
|
-
[x: `embedded-${number}`]: string
|
|
554
|
+
[x: string]: any;
|
|
555
|
+
[x: number]: any;
|
|
556
|
+
[x: symbol]: any;
|
|
557
|
+
[x: `head-${string}`]: string;
|
|
558
|
+
[x: `${string}-tail`]: string;
|
|
559
|
+
[x: `head-${string}-tail`]: string;
|
|
560
|
+
[x: `${bigint}`]: string;
|
|
561
|
+
[x: `embedded-${number}`]: string;
|
|
545
562
|
|
|
546
563
|
// These explicitly defined keys will remain.
|
|
547
564
|
foo: 'bar';
|
|
548
565
|
qux?: 'baz';
|
|
549
|
-
}
|
|
566
|
+
};
|
|
550
567
|
|
|
551
568
|
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
552
569
|
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
@@ -557,7 +574,7 @@ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
|
557
574
|
*/
|
|
558
575
|
type OmitIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType] };
|
|
559
576
|
//#endregion
|
|
560
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
577
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/pick-index-signature.d.ts
|
|
561
578
|
/**
|
|
562
579
|
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
563
580
|
|
|
@@ -605,7 +622,7 @@ type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
|
605
622
|
*/
|
|
606
623
|
type PickIndexSignature<ObjectType> = { [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType] };
|
|
607
624
|
//#endregion
|
|
608
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
625
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/merge.d.ts
|
|
609
626
|
// Merges two objects without worrying about index signatures.
|
|
610
627
|
type SimpleMerge<Destination, Source> = { [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key] } & Source;
|
|
611
628
|
|
|
@@ -616,12 +633,12 @@ Merge two types into a new type. Keys of the second type overrides keys of the f
|
|
|
616
633
|
```
|
|
617
634
|
import type {Merge} from 'type-fest';
|
|
618
635
|
|
|
619
|
-
|
|
636
|
+
type Foo = {
|
|
620
637
|
[x: string]: unknown;
|
|
621
638
|
[x: number]: unknown;
|
|
622
639
|
foo: string;
|
|
623
640
|
bar: symbol;
|
|
624
|
-
}
|
|
641
|
+
};
|
|
625
642
|
|
|
626
643
|
type Bar = {
|
|
627
644
|
[x: number]: number;
|
|
@@ -645,7 +662,7 @@ export type FooBar = Merge<Foo, Bar>;
|
|
|
645
662
|
*/
|
|
646
663
|
type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
|
|
647
664
|
//#endregion
|
|
648
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
665
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/internal/object.d.ts
|
|
649
666
|
/**
|
|
650
667
|
Merges user specified options with default options.
|
|
651
668
|
|
|
@@ -700,7 +717,7 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
700
717
|
*/
|
|
701
718
|
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
702
719
|
//#endregion
|
|
703
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
720
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/except.d.ts
|
|
704
721
|
/**
|
|
705
722
|
Filter out keys from an object.
|
|
706
723
|
|
|
@@ -762,12 +779,14 @@ type Foo = {
|
|
|
762
779
|
type FooWithoutA = Except<Foo, 'a'>;
|
|
763
780
|
//=> {b: string}
|
|
764
781
|
|
|
782
|
+
// @ts-expect-error
|
|
765
783
|
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
766
784
|
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
767
785
|
|
|
768
786
|
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
769
787
|
//=> {a: number} & Partial<Record<"b", never>>
|
|
770
788
|
|
|
789
|
+
// @ts-expect-error
|
|
771
790
|
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
772
791
|
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
773
792
|
|
|
@@ -784,12 +803,12 @@ type UserData = {
|
|
|
784
803
|
|
|
785
804
|
// `Omit` clearly doesn't behave as expected in this case:
|
|
786
805
|
type PostPayload = Omit<UserData, 'email'>;
|
|
787
|
-
//=>
|
|
806
|
+
//=> { [x: string]: string; [x: number]: string; }
|
|
788
807
|
|
|
789
808
|
// In situations like this, `Except` works better.
|
|
790
809
|
// It simply removes the `email` key while preserving all the other keys.
|
|
791
|
-
type
|
|
792
|
-
//=>
|
|
810
|
+
type PostPayloadFixed = Except<UserData, 'email'>;
|
|
811
|
+
//=> { [x: string]: string; name: string; role: 'admin' | 'user'; }
|
|
793
812
|
```
|
|
794
813
|
|
|
795
814
|
@category Object
|
|
@@ -797,7 +816,7 @@ type PostPayload = Except<UserData, 'email'>;
|
|
|
797
816
|
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
|
|
798
817
|
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>> : {});
|
|
799
818
|
//#endregion
|
|
800
|
-
//#region ../../node_modules/.pnpm/type-fest@5.
|
|
819
|
+
//#region ../../node_modules/.pnpm/type-fest@5.3.1/node_modules/type-fest/source/required-deep.d.ts
|
|
801
820
|
/**
|
|
802
821
|
Create a type from another type with all keys and nested keys set to required.
|
|
803
822
|
|