@wix/sdk-types 1.13.8 → 1.13.10

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/build/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { MonitoringClient } from '@wix/monitoring-types';
2
+ import { ConditionalExcept, EmptyObject, Simplify, Paths, SetRequiredDeep } from 'type-fest';
2
3
 
3
4
  type HostModule<T, H extends Host> = {
4
5
  __type: 'host';
@@ -186,783 +187,6 @@ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: Req
186
187
  type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
187
188
  type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
188
189
 
189
- declare global {
190
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
191
- interface SymbolConstructor {
192
- readonly observable: symbol;
193
- }
194
- }
195
-
196
- declare const emptyObjectSymbol: unique symbol;
197
-
198
- /**
199
- Represents a strictly empty plain object, the `{}` value.
200
-
201
- When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
202
-
203
- @example
204
- ```
205
- import type {EmptyObject} from 'type-fest';
206
-
207
- // The following illustrates the problem with `{}`.
208
- const foo1: {} = {}; // Pass
209
- const foo2: {} = []; // Pass
210
- const foo3: {} = 42; // Pass
211
- const foo4: {} = {a: 1}; // Pass
212
-
213
- // With `EmptyObject` only the first case is valid.
214
- const bar1: EmptyObject = {}; // Pass
215
- const bar2: EmptyObject = 42; // Fail
216
- const bar3: EmptyObject = []; // Fail
217
- const bar4: EmptyObject = {a: 1}; // Fail
218
- ```
219
-
220
- Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
221
-
222
- @category Object
223
- */
224
- type EmptyObject = {[emptyObjectSymbol]?: never};
225
-
226
- /**
227
- Extract all optional keys from the given type.
228
-
229
- This is useful when you want to create a new type that contains different type values for the optional keys only.
230
-
231
- @example
232
- ```
233
- import type {OptionalKeysOf, Except} from 'type-fest';
234
-
235
- interface User {
236
- name: string;
237
- surname: string;
238
-
239
- luckyNumber?: number;
240
- }
241
-
242
- const REMOVE_FIELD = Symbol('remove field symbol');
243
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
244
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
245
- };
246
-
247
- const update1: UpdateOperation<User> = {
248
- name: 'Alice'
249
- };
250
-
251
- const update2: UpdateOperation<User> = {
252
- name: 'Bob',
253
- luckyNumber: REMOVE_FIELD
254
- };
255
- ```
256
-
257
- @category Utilities
258
- */
259
- type OptionalKeysOf<BaseType extends object> =
260
- BaseType extends unknown // For distributing `BaseType`
261
- ? (keyof {
262
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
263
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
264
- : never; // Should never happen
265
-
266
- /**
267
- Extract all required keys from the given type.
268
-
269
- 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...
270
-
271
- @example
272
- ```
273
- import type {RequiredKeysOf} from 'type-fest';
274
-
275
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
276
-
277
- interface User {
278
- name: string;
279
- surname: string;
280
-
281
- luckyNumber?: number;
282
- }
283
-
284
- const validator1 = createValidation<User>('name', value => value.length < 25);
285
- const validator2 = createValidation<User>('surname', value => value.length < 25);
286
- ```
287
-
288
- @category Utilities
289
- */
290
- type RequiredKeysOf<BaseType extends object> =
291
- BaseType extends unknown // For distributing `BaseType`
292
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
293
- : never; // Should never happen
294
-
295
- /**
296
- Returns a boolean for whether the given type is `never`.
297
-
298
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
299
- @link https://stackoverflow.com/a/53984913/10292952
300
- @link https://www.zhenghao.io/posts/ts-never
301
-
302
- Useful in type utilities, such as checking if something does not occur.
303
-
304
- @example
305
- ```
306
- import type {IsNever, And} from 'type-fest';
307
-
308
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
309
- type AreStringsEqual<A extends string, B extends string> =
310
- And<
311
- IsNever<Exclude<A, B>> extends true ? true : false,
312
- IsNever<Exclude<B, A>> extends true ? true : false
313
- >;
314
-
315
- type EndIfEqual<I extends string, O extends string> =
316
- AreStringsEqual<I, O> extends true
317
- ? never
318
- : void;
319
-
320
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
321
- if (input === output) {
322
- process.exit(0);
323
- }
324
- }
325
-
326
- endIfEqual('abc', 'abc');
327
- //=> never
328
-
329
- endIfEqual('abc', '123');
330
- //=> void
331
- ```
332
-
333
- @category Type Guard
334
- @category Utilities
335
- */
336
- type IsNever<T> = [T] extends [never] ? true : false;
337
-
338
- /**
339
- An if-else-like type that resolves depending on whether the given type is `never`.
340
-
341
- @see {@link IsNever}
342
-
343
- @example
344
- ```
345
- import type {IfNever} from 'type-fest';
346
-
347
- type ShouldBeTrue = IfNever<never>;
348
- //=> true
349
-
350
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
351
- //=> 'bar'
352
- ```
353
-
354
- @category Type Guard
355
- @category Utilities
356
- */
357
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
358
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
359
- );
360
-
361
- // Can eventually be replaced with the built-in once this library supports
362
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
363
- type NoInfer<T> = T extends infer U ? U : never;
364
-
365
- /**
366
- Returns a boolean for whether the given type is `any`.
367
-
368
- @link https://stackoverflow.com/a/49928360/1490091
369
-
370
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
371
-
372
- @example
373
- ```
374
- import type {IsAny} from 'type-fest';
375
-
376
- const typedObject = {a: 1, b: 2} as const;
377
- const anyObject: any = {a: 1, b: 2};
378
-
379
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
380
- return obj[key];
381
- }
382
-
383
- const typedA = get(typedObject, 'a');
384
- //=> 1
385
-
386
- const anyA = get(anyObject, 'a');
387
- //=> any
388
- ```
389
-
390
- @category Type Guard
391
- @category Utilities
392
- */
393
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
394
-
395
- /**
396
- Returns a boolean for whether the two given types are equal.
397
-
398
- @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
399
- @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
400
-
401
- Use-cases:
402
- - If you want to make a conditional branch based on the result of a comparison of two types.
403
-
404
- @example
405
- ```
406
- import type {IsEqual} from 'type-fest';
407
-
408
- // This type returns a boolean for whether the given array includes the given item.
409
- // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
410
- type Includes<Value extends readonly any[], Item> =
411
- Value extends readonly [Value[0], ...infer rest]
412
- ? IsEqual<Value[0], Item> extends true
413
- ? true
414
- : Includes<rest, Item>
415
- : false;
416
- ```
417
-
418
- @category Type Guard
419
- @category Utilities
420
- */
421
- type IsEqual<A, B> =
422
- (<G>() => G extends A & G | G ? 1 : 2) extends
423
- (<G>() => G extends B & G | G ? 1 : 2)
424
- ? true
425
- : false;
426
-
427
- /**
428
- 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.
429
-
430
- @example
431
- ```
432
- import type {Simplify} from 'type-fest';
433
-
434
- type PositionProps = {
435
- top: number;
436
- left: number;
437
- };
438
-
439
- type SizeProps = {
440
- width: number;
441
- height: number;
442
- };
443
-
444
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
445
- type Props = Simplify<PositionProps & SizeProps>;
446
- ```
447
-
448
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
449
-
450
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
451
-
452
- @example
453
- ```
454
- import type {Simplify} from 'type-fest';
455
-
456
- interface SomeInterface {
457
- foo: number;
458
- bar?: string;
459
- baz: number | undefined;
460
- }
461
-
462
- type SomeType = {
463
- foo: number;
464
- bar?: string;
465
- baz: number | undefined;
466
- };
467
-
468
- const literal = {foo: 123, bar: 'hello', baz: 456};
469
- const someType: SomeType = literal;
470
- const someInterface: SomeInterface = literal;
471
-
472
- function fn(object: Record<string, unknown>): void {}
473
-
474
- fn(literal); // Good: literal object type is sealed
475
- fn(someType); // Good: type is sealed
476
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
477
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
478
- ```
479
-
480
- @link https://github.com/microsoft/TypeScript/issues/15300
481
- @see SimplifyDeep
482
- @category Object
483
- */
484
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
485
-
486
- /**
487
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
488
-
489
- This is the counterpart of `PickIndexSignature`.
490
-
491
- Use-cases:
492
- - Remove overly permissive signatures from third-party types.
493
-
494
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
495
-
496
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
497
-
498
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
499
-
500
- ```
501
- const indexed: Record<string, unknown> = {}; // Allowed
502
-
503
- const keyed: Record<'foo', unknown> = {}; // Error
504
- // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
505
- ```
506
-
507
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
508
-
509
- ```
510
- type Indexed = {} extends Record<string, unknown>
511
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
512
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
513
- // => '✅ `{}` is assignable to `Record<string, unknown>`'
514
-
515
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
516
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
517
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
518
- // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
519
- ```
520
-
521
- 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`...
522
-
523
- ```
524
- import type {OmitIndexSignature} from 'type-fest';
525
-
526
- type OmitIndexSignature<ObjectType> = {
527
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
528
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
529
- };
530
- ```
531
-
532
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
533
-
534
- ```
535
- import type {OmitIndexSignature} from 'type-fest';
536
-
537
- type OmitIndexSignature<ObjectType> = {
538
- [KeyType in keyof ObjectType
539
- // Is `{}` assignable to `Record<KeyType, unknown>`?
540
- as {} extends Record<KeyType, unknown>
541
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
542
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
543
- ]: ObjectType[KeyType];
544
- };
545
- ```
546
-
547
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
548
-
549
- @example
550
- ```
551
- import type {OmitIndexSignature} from 'type-fest';
552
-
553
- interface Example {
554
- // These index signatures will be removed.
555
- [x: string]: any
556
- [x: number]: any
557
- [x: symbol]: any
558
- [x: `head-${string}`]: string
559
- [x: `${string}-tail`]: string
560
- [x: `head-${string}-tail`]: string
561
- [x: `${bigint}`]: string
562
- [x: `embedded-${number}`]: string
563
-
564
- // These explicitly defined keys will remain.
565
- foo: 'bar';
566
- qux?: 'baz';
567
- }
568
-
569
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
570
- // => { foo: 'bar'; qux?: 'baz' | undefined; }
571
- ```
572
-
573
- @see PickIndexSignature
574
- @category Object
575
- */
576
- type OmitIndexSignature<ObjectType> = {
577
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
578
- ? never
579
- : KeyType]: ObjectType[KeyType];
580
- };
581
-
582
- /**
583
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
584
-
585
- This is the counterpart of `OmitIndexSignature`.
586
-
587
- @example
588
- ```
589
- import type {PickIndexSignature} from 'type-fest';
590
-
591
- declare const symbolKey: unique symbol;
592
-
593
- type Example = {
594
- // These index signatures will remain.
595
- [x: string]: unknown;
596
- [x: number]: unknown;
597
- [x: symbol]: unknown;
598
- [x: `head-${string}`]: string;
599
- [x: `${string}-tail`]: string;
600
- [x: `head-${string}-tail`]: string;
601
- [x: `${bigint}`]: string;
602
- [x: `embedded-${number}`]: string;
603
-
604
- // These explicitly defined keys will be removed.
605
- ['kebab-case-key']: string;
606
- [symbolKey]: string;
607
- foo: 'bar';
608
- qux?: 'baz';
609
- };
610
-
611
- type ExampleIndexSignature = PickIndexSignature<Example>;
612
- // {
613
- // [x: string]: unknown;
614
- // [x: number]: unknown;
615
- // [x: symbol]: unknown;
616
- // [x: `head-${string}`]: string;
617
- // [x: `${string}-tail`]: string;
618
- // [x: `head-${string}-tail`]: string;
619
- // [x: `${bigint}`]: string;
620
- // [x: `embedded-${number}`]: string;
621
- // }
622
- ```
623
-
624
- @see OmitIndexSignature
625
- @category Object
626
- */
627
- type PickIndexSignature<ObjectType> = {
628
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
629
- ? KeyType
630
- : never]: ObjectType[KeyType];
631
- };
632
-
633
- // Merges two objects without worrying about index signatures.
634
- type SimpleMerge<Destination, Source> = {
635
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
636
- } & Source;
637
-
638
- /**
639
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
640
-
641
- @example
642
- ```
643
- import type {Merge} from 'type-fest';
644
-
645
- interface Foo {
646
- [x: string]: unknown;
647
- [x: number]: unknown;
648
- foo: string;
649
- bar: symbol;
650
- }
651
-
652
- type Bar = {
653
- [x: number]: number;
654
- [x: symbol]: unknown;
655
- bar: Date;
656
- baz: boolean;
657
- };
658
-
659
- export type FooBar = Merge<Foo, Bar>;
660
- // => {
661
- // [x: string]: unknown;
662
- // [x: number]: number;
663
- // [x: symbol]: unknown;
664
- // foo: string;
665
- // bar: Date;
666
- // baz: boolean;
667
- // }
668
- ```
669
-
670
- @category Object
671
- */
672
- type Merge<Destination, Source> =
673
- Simplify<
674
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
675
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
676
- >;
677
-
678
- /**
679
- An if-else-like type that resolves depending on whether the given type is `any`.
680
-
681
- @see {@link IsAny}
682
-
683
- @example
684
- ```
685
- import type {IfAny} from 'type-fest';
686
-
687
- type ShouldBeTrue = IfAny<any>;
688
- //=> true
689
-
690
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
691
- //=> 'bar'
692
- ```
693
-
694
- @category Type Guard
695
- @category Utilities
696
- */
697
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
698
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
699
- );
700
-
701
- /**
702
- Merges user specified options with default options.
703
-
704
- @example
705
- ```
706
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
707
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
708
- type SpecifiedOptions = {leavesOnly: true};
709
-
710
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
711
- //=> {maxRecursionDepth: 10; leavesOnly: true}
712
- ```
713
-
714
- @example
715
- ```
716
- // Complains if default values are not provided for optional options
717
-
718
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
719
- type DefaultPathsOptions = {maxRecursionDepth: 10};
720
- type SpecifiedOptions = {};
721
-
722
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
723
- // ~~~~~~~~~~~~~~~~~~~
724
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
725
- ```
726
-
727
- @example
728
- ```
729
- // Complains if an option's default type does not conform to the expected type
730
-
731
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
732
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
733
- type SpecifiedOptions = {};
734
-
735
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
736
- // ~~~~~~~~~~~~~~~~~~~
737
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
738
- ```
739
-
740
- @example
741
- ```
742
- // Complains if an option's specified type does not conform to the expected type
743
-
744
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
745
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
746
- type SpecifiedOptions = {leavesOnly: 'yes'};
747
-
748
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
749
- // ~~~~~~~~~~~~~~~~
750
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
751
- ```
752
- */
753
- type ApplyDefaultOptions<
754
- Options extends object,
755
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
756
- SpecifiedOptions extends Options,
757
- > =
758
- IfAny<SpecifiedOptions, Defaults,
759
- IfNever<SpecifiedOptions, Defaults,
760
- Simplify<Merge<Defaults, {
761
- [Key in keyof SpecifiedOptions
762
- as Key extends OptionalKeysOf<Options>
763
- ? Extract<SpecifiedOptions[Key], undefined> extends never
764
- ? Key
765
- : never
766
- : Key
767
- ]: SpecifiedOptions[Key]
768
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
769
- >>;
770
-
771
- /**
772
- Filter out keys from an object.
773
-
774
- Returns `never` if `Exclude` is strictly equal to `Key`.
775
- Returns `never` if `Key` extends `Exclude`.
776
- Returns `Key` otherwise.
777
-
778
- @example
779
- ```
780
- type Filtered = Filter<'foo', 'foo'>;
781
- //=> never
782
- ```
783
-
784
- @example
785
- ```
786
- type Filtered = Filter<'bar', string>;
787
- //=> never
788
- ```
789
-
790
- @example
791
- ```
792
- type Filtered = Filter<'bar', 'foo'>;
793
- //=> 'bar'
794
- ```
795
-
796
- @see {Except}
797
- */
798
- type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
799
-
800
- type ExceptOptions = {
801
- /**
802
- Disallow assigning non-specified properties.
803
-
804
- Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
805
-
806
- @default false
807
- */
808
- requireExactProps?: boolean;
809
- };
810
-
811
- type DefaultExceptOptions = {
812
- requireExactProps: false;
813
- };
814
-
815
- /**
816
- Create a type from an object type without certain keys.
817
-
818
- We recommend setting the `requireExactProps` option to `true`.
819
-
820
- This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
821
-
822
- This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
823
-
824
- @example
825
- ```
826
- import type {Except} from 'type-fest';
827
-
828
- type Foo = {
829
- a: number;
830
- b: string;
831
- };
832
-
833
- type FooWithoutA = Except<Foo, 'a'>;
834
- //=> {b: string}
835
-
836
- const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
837
- //=> errors: 'a' does not exist in type '{ b: string; }'
838
-
839
- type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
840
- //=> {a: number} & Partial<Record<"b", never>>
841
-
842
- const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
843
- //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
844
-
845
- // The `Omit` utility type doesn't work when omitting specific keys from objects containing index signatures.
846
-
847
- // Consider the following example:
848
-
849
- type UserData = {
850
- [metadata: string]: string;
851
- email: string;
852
- name: string;
853
- role: 'admin' | 'user';
854
- };
855
-
856
- // `Omit` clearly doesn't behave as expected in this case:
857
- type PostPayload = Omit<UserData, 'email'>;
858
- //=> type PostPayload = { [x: string]: string; [x: number]: string; }
859
-
860
- // In situations like this, `Except` works better.
861
- // It simply removes the `email` key while preserving all the other keys.
862
- type PostPayload = Except<UserData, 'email'>;
863
- //=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
864
- ```
865
-
866
- @category Object
867
- */
868
- type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> =
869
- _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
870
-
871
- type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
872
- [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
873
- } & (Options['requireExactProps'] extends true
874
- ? Partial<Record<KeysType, never>>
875
- : {});
876
-
877
- /**
878
- Extract the keys from a type where the value type of the key extends the given `Condition`.
879
-
880
- Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
881
-
882
- @example
883
- ```
884
- import type {ConditionalKeys} from 'type-fest';
885
-
886
- interface Example {
887
- a: string;
888
- b: string | number;
889
- c?: string;
890
- d: {};
891
- }
892
-
893
- type StringKeysOnly = ConditionalKeys<Example, string>;
894
- //=> 'a'
895
- ```
896
-
897
- To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
898
-
899
- @example
900
- ```
901
- import type {ConditionalKeys} from 'type-fest';
902
-
903
- type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
904
- //=> 'a' | 'c'
905
- ```
906
-
907
- @category Object
908
- */
909
- type ConditionalKeys<Base, Condition> =
910
- {
911
- // Map through all the keys of the given base type.
912
- [Key in keyof Base]-?:
913
- // Pick only keys with types extending the given `Condition` type.
914
- Base[Key] extends Condition
915
- // Retain this key
916
- // If the value for the key extends never, only include it if `Condition` also extends never
917
- ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
918
- // Discard this key since the condition fails.
919
- : never;
920
- // Convert the produced object into a union type of the keys which passed the conditional test.
921
- }[keyof Base];
922
-
923
- /**
924
- Exclude keys from a shape that matches the given `Condition`.
925
-
926
- This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
927
-
928
- @example
929
- ```
930
- import type {Primitive, ConditionalExcept} from 'type-fest';
931
-
932
- class Awesome {
933
- name: string;
934
- successes: number;
935
- failures: bigint;
936
-
937
- run() {}
938
- }
939
-
940
- type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
941
- //=> {run: () => void}
942
- ```
943
-
944
- @example
945
- ```
946
- import type {ConditionalExcept} from 'type-fest';
947
-
948
- interface Example {
949
- a: string;
950
- b: string | number;
951
- c: () => void;
952
- d: {};
953
- }
954
-
955
- type NonStringKeysOnly = ConditionalExcept<Example, string>;
956
- //=> {b: string | number; c: () => void; d: {}}
957
- ```
958
-
959
- @category Object
960
- */
961
- type ConditionalExcept<Base, Condition> = Except<
962
- Base,
963
- ConditionalKeys<Base, Condition>
964
- >;
965
-
966
190
  /**
967
191
  * Descriptors are objects that describe the API of a module, and the module
968
192
  * can either be a REST module or a host module.
@@ -1061,4 +285,22 @@ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalT
1061
285
  alpha: true;
1062
286
  } ? T : never;
1063
287
 
1064
- export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
288
+ declare global {
289
+ /**
290
+ * A global interface to set the type mode for the SDK.
291
+ * @example
292
+ * ```ts
293
+ * declare global {
294
+ * interface SDKTypeMode {
295
+ * strict: true;
296
+ * }
297
+ * }
298
+ */
299
+ interface SDKTypeMode {
300
+ }
301
+ }
302
+ type NonNullablePaths<T, K extends Paths<T>> = globalThis.SDKTypeMode extends {
303
+ strict: true;
304
+ } ? SetRequiredDeep<T, K> : T;
305
+
306
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type NonNullablePaths, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };