serverless-spy 0.0.61 → 0.0.63

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.
Files changed (99) hide show
  1. package/.jsii +3 -2
  2. package/_config.yml +15 -3
  3. package/_includes/head/custom.html +6 -0
  4. package/assets/images/site-logo.png +0 -0
  5. package/dist/releasetag.txt +1 -1
  6. package/extension/interceptor.ts +5 -1
  7. package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js +147 -2
  8. package/lib/extension/dist/layer/nodejs/node_modules/interceptor.js.map +4 -4
  9. package/lib/src/ServerlessSpy.js +1 -1
  10. package/logo/full_logo.png +0 -0
  11. package/node_modules/serialize-error/error-constructors.d.ts +8 -0
  12. package/node_modules/serialize-error/error-constructors.js +26 -0
  13. package/node_modules/serialize-error/index.d.ts +171 -0
  14. package/node_modules/serialize-error/index.js +205 -0
  15. package/node_modules/serialize-error/license +9 -0
  16. package/node_modules/serialize-error/node_modules/type-fest/index.d.ts +95 -0
  17. package/node_modules/serialize-error/node_modules/type-fest/package.json +52 -0
  18. package/node_modules/serialize-error/node_modules/type-fest/readme.md +905 -0
  19. package/node_modules/serialize-error/node_modules/type-fest/source/async-return-type.d.ts +25 -0
  20. package/node_modules/serialize-error/node_modules/type-fest/source/asyncify.d.ts +33 -0
  21. package/node_modules/serialize-error/node_modules/type-fest/source/basic.d.ts +45 -0
  22. package/node_modules/serialize-error/node_modules/type-fest/source/camel-case.d.ts +73 -0
  23. package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties-deep.d.ts +54 -0
  24. package/node_modules/serialize-error/node_modules/type-fest/source/camel-cased-properties.d.ts +36 -0
  25. package/node_modules/serialize-error/node_modules/type-fest/source/conditional-except.d.ts +45 -0
  26. package/node_modules/serialize-error/node_modules/type-fest/source/conditional-keys.d.ts +47 -0
  27. package/node_modules/serialize-error/node_modules/type-fest/source/conditional-pick.d.ts +44 -0
  28. package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-case.d.ts +93 -0
  29. package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-cased-properties-deep.d.ts +60 -0
  30. package/node_modules/serialize-error/node_modules/type-fest/source/delimiter-cased-properties.d.ts +37 -0
  31. package/node_modules/serialize-error/node_modules/type-fest/source/entries.d.ts +62 -0
  32. package/node_modules/serialize-error/node_modules/type-fest/source/entry.d.ts +65 -0
  33. package/node_modules/serialize-error/node_modules/type-fest/source/exact.d.ts +73 -0
  34. package/node_modules/serialize-error/node_modules/type-fest/source/except.d.ts +57 -0
  35. package/node_modules/serialize-error/node_modules/type-fest/source/fixed-length-array.d.ts +43 -0
  36. package/node_modules/serialize-error/node_modules/type-fest/source/get.d.ts +184 -0
  37. package/node_modules/serialize-error/node_modules/type-fest/source/has-optional-keys.d.ts +21 -0
  38. package/node_modules/serialize-error/node_modules/type-fest/source/has-required-keys.d.ts +59 -0
  39. package/node_modules/serialize-error/node_modules/type-fest/source/includes.d.ts +22 -0
  40. package/node_modules/serialize-error/node_modules/type-fest/source/internal.d.ts +59 -0
  41. package/node_modules/serialize-error/node_modules/type-fest/source/invariant-of.d.ts +76 -0
  42. package/node_modules/serialize-error/node_modules/type-fest/source/iterable-element.d.ts +54 -0
  43. package/node_modules/serialize-error/node_modules/type-fest/source/join.d.ts +30 -0
  44. package/node_modules/serialize-error/node_modules/type-fest/source/jsonify.d.ts +90 -0
  45. package/node_modules/serialize-error/node_modules/type-fest/source/kebab-case.d.ts +38 -0
  46. package/node_modules/serialize-error/node_modules/type-fest/source/kebab-cased-properties-deep.d.ts +47 -0
  47. package/node_modules/serialize-error/node_modules/type-fest/source/kebab-cased-properties.d.ts +30 -0
  48. package/node_modules/serialize-error/node_modules/type-fest/source/last-array-element.d.ts +28 -0
  49. package/node_modules/serialize-error/node_modules/type-fest/source/literal-to-primitive.d.ts +36 -0
  50. package/node_modules/serialize-error/node_modules/type-fest/source/literal-union.d.ts +35 -0
  51. package/node_modules/serialize-error/node_modules/type-fest/source/merge-exclusive.d.ts +41 -0
  52. package/node_modules/serialize-error/node_modules/type-fest/source/merge.d.ts +27 -0
  53. package/node_modules/serialize-error/node_modules/type-fest/source/multidimensional-array.d.ts +43 -0
  54. package/node_modules/serialize-error/node_modules/type-fest/source/multidimensional-readonly-array.d.ts +47 -0
  55. package/node_modules/serialize-error/node_modules/type-fest/source/mutable.d.ts +5 -0
  56. package/node_modules/serialize-error/node_modules/type-fest/source/numeric.d.ts +170 -0
  57. package/node_modules/serialize-error/node_modules/type-fest/source/observable-like.d.ts +62 -0
  58. package/node_modules/serialize-error/node_modules/type-fest/source/opaque.d.ts +107 -0
  59. package/node_modules/serialize-error/node_modules/type-fest/source/optional-keys-of.d.ts +38 -0
  60. package/node_modules/serialize-error/node_modules/type-fest/source/package-json.d.ts +663 -0
  61. package/node_modules/serialize-error/node_modules/type-fest/source/partial-deep.d.ts +113 -0
  62. package/node_modules/serialize-error/node_modules/type-fest/source/partial-on-undefined-deep.d.ts +70 -0
  63. package/node_modules/serialize-error/node_modules/type-fest/source/pascal-case.d.ts +38 -0
  64. package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties-deep.d.ts +54 -0
  65. package/node_modules/serialize-error/node_modules/type-fest/source/pascal-cased-properties.d.ts +34 -0
  66. package/node_modules/serialize-error/node_modules/type-fest/source/primitive.d.ts +13 -0
  67. package/node_modules/serialize-error/node_modules/type-fest/source/promisable.d.ts +25 -0
  68. package/node_modules/serialize-error/node_modules/type-fest/source/promise-value.d.ts +29 -0
  69. package/node_modules/serialize-error/node_modules/type-fest/source/readonly-deep.d.ts +85 -0
  70. package/node_modules/serialize-error/node_modules/type-fest/source/readonly-tuple.d.ts +41 -0
  71. package/node_modules/serialize-error/node_modules/type-fest/source/remove-index-signature.d.ts +104 -0
  72. package/node_modules/serialize-error/node_modules/type-fest/source/replace.d.ts +67 -0
  73. package/node_modules/serialize-error/node_modules/type-fest/source/require-all-or-none.d.ts +36 -0
  74. package/node_modules/serialize-error/node_modules/type-fest/source/require-at-least-one.d.ts +35 -0
  75. package/node_modules/serialize-error/node_modules/type-fest/source/require-exactly-one.d.ts +34 -0
  76. package/node_modules/serialize-error/node_modules/type-fest/source/required-keys-of.d.ts +29 -0
  77. package/node_modules/serialize-error/node_modules/type-fest/source/schema.d.ts +72 -0
  78. package/node_modules/serialize-error/node_modules/type-fest/source/screaming-snake-case.d.ts +33 -0
  79. package/node_modules/serialize-error/node_modules/type-fest/source/set-non-nullable.d.ts +35 -0
  80. package/node_modules/serialize-error/node_modules/type-fest/source/set-optional.d.ts +35 -0
  81. package/node_modules/serialize-error/node_modules/type-fest/source/set-required.d.ts +35 -0
  82. package/node_modules/serialize-error/node_modules/type-fest/source/set-return-type.d.ts +31 -0
  83. package/node_modules/serialize-error/node_modules/type-fest/source/simplify.d.ts +83 -0
  84. package/node_modules/serialize-error/node_modules/type-fest/source/snake-case.d.ts +38 -0
  85. package/node_modules/serialize-error/node_modules/type-fest/source/snake-cased-properties-deep.d.ts +47 -0
  86. package/node_modules/serialize-error/node_modules/type-fest/source/snake-cased-properties.d.ts +30 -0
  87. package/node_modules/serialize-error/node_modules/type-fest/source/split.d.ts +29 -0
  88. package/node_modules/serialize-error/node_modules/type-fest/source/spread.d.ts +85 -0
  89. package/node_modules/serialize-error/node_modules/type-fest/source/string-key-of.d.ts +25 -0
  90. package/node_modules/serialize-error/node_modules/type-fest/source/stringified.d.ts +23 -0
  91. package/node_modules/serialize-error/node_modules/type-fest/source/trim.d.ts +25 -0
  92. package/node_modules/serialize-error/node_modules/type-fest/source/tsconfig-json.d.ts +1172 -0
  93. package/node_modules/serialize-error/node_modules/type-fest/source/typed-array.d.ts +17 -0
  94. package/node_modules/serialize-error/node_modules/type-fest/source/union-to-intersection.d.ts +60 -0
  95. package/node_modules/serialize-error/node_modules/type-fest/source/value-of.d.ts +42 -0
  96. package/node_modules/serialize-error/node_modules/type-fest/source/writable.d.ts +40 -0
  97. package/node_modules/serialize-error/package.json +46 -0
  98. package/node_modules/serialize-error/readme.md +198 -0
  99. package/package.json +6 -4
@@ -0,0 +1,54 @@
1
+ /**
2
+ Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
3
+
4
+ This can be useful, for example, if you want to get the type that is yielded in a generator function. Often the return type of those functions are not specified.
5
+
6
+ This type works with both `Iterable`s and `AsyncIterable`s, so it can be use with synchronous and asynchronous generators.
7
+
8
+ Here is an example of `IterableElement` in action with a generator function:
9
+
10
+ @example
11
+ ```
12
+ import type {IterableElement} from 'type-fest';
13
+
14
+ function * iAmGenerator() {
15
+ yield 1;
16
+ yield 2;
17
+ }
18
+
19
+ type MeNumber = IterableElement<ReturnType<typeof iAmGenerator>>
20
+ ```
21
+
22
+ And here is an example with an async generator:
23
+
24
+ @example
25
+ ```
26
+ import type {IterableElement} from 'type-fest';
27
+
28
+ async function * iAmGeneratorAsync() {
29
+ yield 'hi';
30
+ yield true;
31
+ }
32
+
33
+ type MeStringOrBoolean = IterableElement<ReturnType<typeof iAmGeneratorAsync>>
34
+ ```
35
+
36
+ Many types in JavaScript/TypeScript are iterables. This type works on all types that implement those interfaces. For example, `Array`, `Set`, `Map`, `stream.Readable`, etc.
37
+
38
+ An example with an array of strings:
39
+
40
+ @example
41
+ ```
42
+ import type {IterableElement} from 'type-fest';
43
+
44
+ type MeString = IterableElement<string[]>
45
+ ```
46
+
47
+ @category Iterable
48
+ */
49
+ export type IterableElement<TargetIterable> =
50
+ TargetIterable extends Iterable<infer ElementType> ?
51
+ ElementType :
52
+ TargetIterable extends AsyncIterable<infer ElementType> ?
53
+ ElementType :
54
+ never;
@@ -0,0 +1,30 @@
1
+ /**
2
+ Join an array of strings and/or numbers using the given string as a delimiter.
3
+
4
+ Use-case: Defining key paths in a nested object. For example, for dot-notation fields in MongoDB queries.
5
+
6
+ @example
7
+ ```
8
+ import type {Join} from 'type-fest';
9
+
10
+ // Mixed (strings & numbers) items; result is: 'foo.0.baz'
11
+ const path: Join<['foo', 0, 'baz'], '.'> = ['foo', 0, 'baz'].join('.');
12
+
13
+ // Only string items; result is: 'foo.bar.baz'
14
+ const path: Join<['foo', 'bar', 'baz'], '.'> = ['foo', 'bar', 'baz'].join('.');
15
+
16
+ // Only number items; result is: '1.2.3'
17
+ const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
18
+ ```
19
+
20
+ @category Array
21
+ @category Template literal
22
+ */
23
+ export type Join<
24
+ Strings extends Array<string | number>,
25
+ Delimiter extends string,
26
+ > = Strings extends [] ? '' :
27
+ Strings extends [string | number] ? `${Strings[0]}` :
28
+ // @ts-expect-error `Rest` is inferred as `unknown` here: https://github.com/microsoft/TypeScript/issues/45281
29
+ Strings extends [string | number, ...infer Rest] ? `${Strings[0]}${Delimiter}${Join<Rest, Delimiter>}` :
30
+ string;
@@ -0,0 +1,90 @@
1
+ import type {JsonPrimitive, JsonValue} from './basic';
2
+ import {Finite, NegativeInfinity, PositiveInfinity} from './numeric';
3
+ import {TypedArray} from './typed-array';
4
+
5
+ // Note: The return value has to be `any` and not `unknown` so it can match `void`.
6
+ type NotJsonable = ((...args: any[]) => any) | undefined | symbol;
7
+
8
+ /**
9
+ Transform a type to one that is assignable to the `JsonValue` type.
10
+
11
+ This includes:
12
+ 1. Transforming JSON `interface` to a `type` that is assignable to `JsonValue`.
13
+ 2. Transforming non-JSON value that is *jsonable* to a type that is assignable to `JsonValue`, where *jsonable* means the non-JSON value implements the `.toJSON()` method that returns a value that is assignable to `JsonValue`.
14
+
15
+ @remarks
16
+
17
+ An interface cannot be structurally compared to `JsonValue` because an interface can be re-opened to add properties that may not be satisfy `JsonValue`.
18
+
19
+ @example
20
+ ```
21
+ import type {Jsonify} from 'type-fest';
22
+
23
+ interface Geometry {
24
+ type: 'Point' | 'Polygon';
25
+ coordinates: [number, number];
26
+ }
27
+
28
+ const point: Geometry = {
29
+ type: 'Point',
30
+ coordinates: [1, 1]
31
+ };
32
+
33
+ const problemFn = (data: JsonValue) => {
34
+ // Does something with data
35
+ };
36
+
37
+ problemFn(point); // Error: type Geometry is not assignable to parameter of type JsonValue because it is an interface
38
+
39
+ const fixedFn = <T>(data: Jsonify<T>) => {
40
+ // Does something with data
41
+ };
42
+
43
+ fixedFn(point); // Good: point is assignable. Jsonify<T> transforms Geometry into value assignable to JsonValue
44
+ fixedFn(new Date()); // Error: As expected, Date is not assignable. Jsonify<T> cannot transforms Date into value assignable to JsonValue
45
+ ```
46
+
47
+ Non-JSON values such as `Date` implement `.toJSON()`, so they can be transformed to a value assignable to `JsonValue`:
48
+
49
+ @example
50
+ ```
51
+ import type {Jsonify} from 'type-fest';
52
+
53
+ const time = {
54
+ timeValue: new Date()
55
+ };
56
+
57
+ // `Jsonify<typeof time>` is equivalent to `{timeValue: string}`
58
+ const timeJson = JSON.parse(JSON.stringify(time)) as Jsonify<typeof time>;
59
+ ```
60
+
61
+ @link https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-710744173
62
+
63
+ @category JSON
64
+ */
65
+ type Jsonify<T> =
66
+ // Check if there are any non-JSONable types represented in the union.
67
+ // Note: The use of tuples in this first condition side-steps distributive conditional types
68
+ // (see https://github.com/microsoft/TypeScript/issues/29368#issuecomment-453529532)
69
+ [Extract<T, NotJsonable | bigint>] extends [never]
70
+ ? T extends PositiveInfinity | NegativeInfinity ? null
71
+ : T extends JsonPrimitive ? T // Primitive is acceptable
72
+ : T extends object
73
+ // Any object with toJSON is special case
74
+ ? T extends {toJSON(): infer J} ? (() => J) extends (() => JsonValue) // Is J assignable to JsonValue?
75
+ ? J // Then T is Jsonable and its Jsonable value is J
76
+ : never // Not Jsonable because its toJSON() method does not return JsonValue
77
+ // Instanced primitives are objects
78
+ : T extends Number ? number
79
+ : T extends String ? string
80
+ : T extends Boolean ? boolean
81
+ : T extends Map<any, any> | Set<any> ? {}
82
+ : T extends TypedArray ? Record<string, number>
83
+ : T extends any[]
84
+ ? {[I in keyof T]: T[I] extends NotJsonable ? null : Jsonify<T[I]>}
85
+ : {[P in keyof T as P extends symbol ? never
86
+ : T[P] extends NotJsonable ? never
87
+ : P
88
+ ]: Jsonify<Required<T>[P]>} // Recursive call for its children
89
+ : never // Otherwise any other non-object is removed
90
+ : never; // Otherwise non-JSONable type union was found not empty
@@ -0,0 +1,38 @@
1
+ import type {DelimiterCase} from './delimiter-case';
2
+
3
+ /**
4
+ Convert a string literal to kebab-case.
5
+
6
+ This can be useful when, for example, converting a camel-cased object property to a kebab-cased CSS class name or a command-line flag.
7
+
8
+ @example
9
+ ```
10
+ import type {KebabCase} from 'type-fest';
11
+
12
+ // Simple
13
+
14
+ const someVariable: KebabCase<'fooBar'> = 'foo-bar';
15
+
16
+ // Advanced
17
+
18
+ type KebabCasedProperties<T> = {
19
+ [K in keyof T as KebabCase<K>]: T[K]
20
+ };
21
+
22
+ interface CliOptions {
23
+ dryRun: boolean;
24
+ includeFile: string;
25
+ foo: number;
26
+ }
27
+
28
+ const rawCliOptions: KebabCasedProperties<CliOptions> = {
29
+ 'dry-run': true,
30
+ 'include-file': 'bar.js',
31
+ foo: 123
32
+ };
33
+ ```
34
+
35
+ @category Change case
36
+ @category Template literal
37
+ */
38
+ export type KebabCase<Value> = DelimiterCase<Value, '-'>;
@@ -0,0 +1,47 @@
1
+ import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
2
+
3
+ /**
4
+ Convert object properties to kebab case recursively.
5
+
6
+ This can be useful when, for example, converting some API types from a different style.
7
+
8
+ @see KebabCase
9
+ @see KebabCasedProperties
10
+
11
+ @example
12
+ ```
13
+ import type [KebabCasedPropertiesDeep] from 'type-fest';
14
+
15
+ interface User {
16
+ userId: number;
17
+ userName: string;
18
+ }
19
+
20
+ interface UserWithFriends {
21
+ userInfo: User;
22
+ userFriends: User[];
23
+ }
24
+
25
+ const result: KebabCasedPropertiesDeep<UserWithFriends> = {
26
+ 'user-info': {
27
+ 'user-id': 1,
28
+ 'user-name': 'Tom',
29
+ },
30
+ 'user-friends': [
31
+ {
32
+ 'user-id': 2,
33
+ 'user-name': 'Jerry',
34
+ },
35
+ {
36
+ 'user-id': 3,
37
+ 'user-name': 'Spike',
38
+ },
39
+ ],
40
+ };
41
+ ```
42
+
43
+ @category Change case
44
+ @category Template literal
45
+ @category Object
46
+ */
47
+ export type KebabCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '-'>;
@@ -0,0 +1,30 @@
1
+ import type {DelimiterCasedProperties} from './delimiter-cased-properties';
2
+
3
+ /**
4
+ Convert object properties to kebab case but not recursively.
5
+
6
+ This can be useful when, for example, converting some API types from a different style.
7
+
8
+ @see KebabCase
9
+ @see KebabCasedPropertiesDeep
10
+
11
+ @example
12
+ ```
13
+ import type {KebabCasedProperties} from 'type-fest';
14
+
15
+ interface User {
16
+ userId: number;
17
+ userName: string;
18
+ }
19
+
20
+ const result: KebabCasedProperties<User> = {
21
+ 'user-id': 1,
22
+ 'user-name': 'Tom',
23
+ };
24
+ ```
25
+
26
+ @category Change case
27
+ @category Template literal
28
+ @category Object
29
+ */
30
+ export type KebabCasedProperties<Value> = DelimiterCasedProperties<Value, '-'>;
@@ -0,0 +1,28 @@
1
+ /**
2
+ Extracts the type of the last element of an array.
3
+
4
+ Use-case: Defining the return type of functions that extract the last element of an array, for example [`lodash.last`](https://lodash.com/docs/4.17.15#last).
5
+
6
+ @example
7
+ ```
8
+ import type {LastArrayElement} from 'type-fest';
9
+
10
+ declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;
11
+
12
+ const array = ['foo', 2];
13
+
14
+ typeof lastOf(array);
15
+ //=> number
16
+ ```
17
+
18
+ @category Array
19
+ @category Template literal
20
+ */
21
+ export type LastArrayElement<ValueType extends readonly unknown[]> =
22
+ ValueType extends readonly [infer ElementType]
23
+ ? ElementType
24
+ : ValueType extends readonly [infer _, ...infer Tail]
25
+ ? LastArrayElement<Tail>
26
+ : ValueType extends ReadonlyArray<infer ElementType>
27
+ ? ElementType
28
+ : never;
@@ -0,0 +1,36 @@
1
+ /**
2
+ Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive.
3
+
4
+ Use-case: Working with generic types that may be literal types.
5
+
6
+ @example
7
+ ```
8
+ import type {LiteralToPrimitive} from 'type-fest';
9
+
10
+ // No overloads needed to get the correct return type
11
+ function plus<T extends number | bigint | string>(x: T, y: T): LiteralToPrimitive<T> {
12
+ return x + (y as any);
13
+ }
14
+
15
+ plus('a', 'b'); // string
16
+ plus(1, 2); // number
17
+ plus(1n, 2n); // bigint
18
+ ```
19
+
20
+ @category Type
21
+ */
22
+ export type LiteralToPrimitive<T> = T extends number
23
+ ? number
24
+ : T extends bigint
25
+ ? bigint
26
+ : T extends string
27
+ ? string
28
+ : T extends boolean
29
+ ? boolean
30
+ : T extends symbol
31
+ ? symbol
32
+ : T extends null
33
+ ? null
34
+ : T extends undefined
35
+ ? undefined
36
+ : never;
@@ -0,0 +1,35 @@
1
+ import type {Primitive} from './primitive';
2
+
3
+ /**
4
+ Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
5
+
6
+ Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
7
+
8
+ This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
9
+
10
+ @example
11
+ ```
12
+ import type {LiteralUnion} from 'type-fest';
13
+
14
+ // Before
15
+
16
+ type Pet = 'dog' | 'cat' | string;
17
+
18
+ const pet: Pet = '';
19
+ // Start typing in your TypeScript-enabled IDE.
20
+ // You **will not** get auto-completion for `dog` and `cat` literals.
21
+
22
+ // After
23
+
24
+ type Pet2 = LiteralUnion<'dog' | 'cat', string>;
25
+
26
+ const pet: Pet2 = '';
27
+ // You **will** get auto-completion for `dog` and `cat` literals.
28
+ ```
29
+
30
+ @category Type
31
+ */
32
+ export type LiteralUnion<
33
+ LiteralType,
34
+ BaseType extends Primitive,
35
+ > = LiteralType | (BaseType & Record<never, never>);
@@ -0,0 +1,41 @@
1
+ // Helper type. Not useful on its own.
2
+ type Without<FirstType, SecondType> = {[KeyType in Exclude<keyof FirstType, keyof SecondType>]?: never};
3
+
4
+ /**
5
+ Create a type that has mutually exclusive keys.
6
+
7
+ This type was inspired by [this comment](https://github.com/Microsoft/TypeScript/issues/14094#issuecomment-373782604).
8
+
9
+ This type works with a helper type, called `Without`. `Without<FirstType, SecondType>` produces a type that has only keys from `FirstType` which are not present on `SecondType` and sets the value type for these keys to `never`. This helper type is then used in `MergeExclusive` to remove keys from either `FirstType` or `SecondType`.
10
+
11
+ @example
12
+ ```
13
+ import type {MergeExclusive} from 'type-fest';
14
+
15
+ interface ExclusiveVariation1 {
16
+ exclusive1: boolean;
17
+ }
18
+
19
+ interface ExclusiveVariation2 {
20
+ exclusive2: string;
21
+ }
22
+
23
+ type ExclusiveOptions = MergeExclusive<ExclusiveVariation1, ExclusiveVariation2>;
24
+
25
+ let exclusiveOptions: ExclusiveOptions;
26
+
27
+ exclusiveOptions = {exclusive1: true};
28
+ //=> Works
29
+ exclusiveOptions = {exclusive2: 'hi'};
30
+ //=> Works
31
+ exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
32
+ //=> Error
33
+ ```
34
+
35
+ @category Object
36
+ */
37
+ export type MergeExclusive<FirstType, SecondType> =
38
+ (FirstType | SecondType) extends object ?
39
+ (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
40
+ FirstType | SecondType;
41
+
@@ -0,0 +1,27 @@
1
+ import type {Except} from './except';
2
+ import type {Simplify} from './simplify';
3
+
4
+ type Merge_<FirstType, SecondType> = Except<FirstType, Extract<keyof FirstType, keyof SecondType>> & SecondType;
5
+
6
+ /**
7
+ Merge two types into a new type. Keys of the second type overrides keys of the first type.
8
+
9
+ @example
10
+ ```
11
+ import type {Merge} from 'type-fest';
12
+
13
+ type Foo = {
14
+ a: number;
15
+ b: string;
16
+ };
17
+
18
+ type Bar = {
19
+ b: number;
20
+ };
21
+
22
+ const ab: Merge<Foo, Bar> = {a: 1, b: 2};
23
+ ```
24
+
25
+ @category Object
26
+ */
27
+ export type Merge<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>;
@@ -0,0 +1,43 @@
1
+ import type {IsEqual, Subtract} from './internal';
2
+
3
+ type Recursive<T> = Array<Recursive<T>>;
4
+
5
+ /**
6
+ Creates a type that represents a multidimensional array of the given type and dimension.
7
+
8
+ Use-cases:
9
+ - Return a n-dimensional array from functions.
10
+ - Declare a n-dimensional array by defining its dimensions rather than declaring `[]` repetitively.
11
+ - Infer the dimensions of a n-dimensional array automatically from function arguments.
12
+ - Avoid the need to know in advance the dimensions of a n-dimensional array allowing them to be dynamic.
13
+
14
+ @example
15
+ ```
16
+ import type {MultidimensionalArray} from 'type-fest';
17
+
18
+ function emptyMatrix<T extends number>(dimensions: T): MultidimensionalArray<unknown, T> {
19
+ const matrix: unknown[] = [];
20
+
21
+ let subMatrix = matrix;
22
+ for (let dimension = 1; dimension < dimensions; ++dimension) {
23
+ console.log(`Initializing dimension #${dimension}`);
24
+
25
+ subMatrix[0] = [];
26
+ subMatrix = subMatrix[0] as unknown[];
27
+ }
28
+
29
+ return matrix as MultidimensionalArray<unknown, T>;
30
+ }
31
+
32
+ const matrix = emptyMatrix(3);
33
+
34
+ matrix[0][0][0] = 42;
35
+ ```
36
+
37
+ @category Array
38
+ */
39
+ export type MultidimensionalArray<Element, Dimensions extends number> = number extends Dimensions
40
+ ? Recursive<Element>
41
+ : IsEqual<Dimensions, 0> extends true
42
+ ? Element
43
+ : Array<MultidimensionalArray<Element, Subtract<Dimensions, 1>>>;
@@ -0,0 +1,47 @@
1
+ import type {IsEqual, Subtract} from './internal';
2
+
3
+ type Recursive<T> = ReadonlyArray<Recursive<T>>;
4
+
5
+ /**
6
+ Creates a type that represents a multidimensional readonly array that of the given type and dimension.
7
+
8
+ Use-cases:
9
+ - Return a n-dimensional array from functions.
10
+ - Declare a n-dimensional array by defining its dimensions rather than declaring `[]` repetitively.
11
+ - Infer the dimensions of a n-dimensional array automatically from function arguments.
12
+ - Avoid the need to know in advance the dimensions of a n-dimensional array allowing them to be dynamic.
13
+
14
+ @example
15
+ ```
16
+ import type {MultidimensionalReadonlyArray} from 'type-fest';
17
+
18
+ function emptyMatrix<T extends number>(dimensions: T): MultidimensionalReadonlyArray<unknown, T> {
19
+ const matrix: unknown[] = [];
20
+
21
+ let subMatrix = matrix;
22
+ for (let dimension = 1; dimension < dimensions; ++dimension) {
23
+ console.log(`Initializing dimension #${dimension}`);
24
+
25
+ subMatrix[0] = [];
26
+ if (dimension < dimensions - 1) {
27
+ subMatrix = subMatrix[0] as unknown[];
28
+ } else {
29
+ subMatrix[0] = 42;
30
+ }
31
+ }
32
+
33
+ return matrix as MultidimensionalReadonlyArray<unknown, T>;
34
+ }
35
+
36
+ const matrix = emptyMatrix(3);
37
+
38
+ const answer = matrix[0][0][0]; // 42
39
+ ```
40
+
41
+ @category Array
42
+ */
43
+ export type MultidimensionalReadonlyArray<Element, Dimensions extends number> = number extends Dimensions
44
+ ? Recursive<Element>
45
+ : IsEqual<Dimensions, 0> extends true
46
+ ? Element
47
+ : ReadonlyArray<MultidimensionalReadonlyArray<Element, Subtract<Dimensions, 1>>>;
@@ -0,0 +1,5 @@
1
+ import type {Writable} from './writable';
2
+
3
+ /** @deprecated @see Writable */
4
+ export type Mutable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
5
+ Writable<BaseType, Keys>;