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,905 @@
1
+ <div align="center">
2
+ <br>
3
+ <br>
4
+ <img src="media/logo.svg" alt="type-fest" height="300">
5
+ <br>
6
+ <br>
7
+ <b>A collection of essential TypeScript types</b>
8
+ <br>
9
+ <br>
10
+ <br>
11
+ <br>
12
+ <hr>
13
+ <div align="center">
14
+ <p>
15
+ <p>
16
+ <sup>
17
+ <a href="https://github.com/sponsors/sindresorhus">Sindre Sorhus' open source work is supported by the community</a>
18
+ </sup>
19
+ </p>
20
+ <sup>Special thanks to:</sup>
21
+ <br>
22
+ <br>
23
+ <a href="https://standardresume.co/tech">
24
+ <img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="180"/>
25
+ </a>
26
+ <br>
27
+ <br>
28
+ <br>
29
+ <a href="https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=type-fest&utm_source=github">
30
+ <div>
31
+ <img src="https://sindresorhus.com/assets/thanks/workos-logo-white-bg.svg" width="220" alt="WorkOS">
32
+ </div>
33
+ <b>Your app, enterprise-ready.</b>
34
+ <div>
35
+ <sub>Start selling to enterprise customers with just a few lines of code.</sub>
36
+ <br>
37
+ <sup>Add Single Sign-On (and more) in minutes instead of months.</sup>
38
+ </div>
39
+ </a>
40
+ <br>
41
+ <br>
42
+ <br>
43
+ <a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-light-mode-only">
44
+ <div>
45
+ <img src="https://sindresorhus.com/assets/thanks/anvil-logo-light.svg" width="200" alt="Anvil">
46
+ </div>
47
+ <br>
48
+ <b>Paperwork that makes the data work.</b>
49
+ <div>
50
+ <sub>
51
+ Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
52
+ <br>
53
+ The easiest way to build paperwork automation into your product.
54
+ </sub>
55
+ </div>
56
+ </a>
57
+ <a href="https://www.useanvil.com/?utm_source=sindresorhus#gh-dark-mode-only">
58
+ <div>
59
+ <img src="https://sindresorhus.com/assets/thanks/anvil-logo-dark.svg" width="200" alt="Anvil">
60
+ </div>
61
+ <br>
62
+ <b>Paperwork that makes the data work.</b>
63
+ <div>
64
+ <sub>
65
+ Easy APIs for paperwork. PDF generation, e-signature and embeddable no-code webforms.
66
+ <br>
67
+ The easiest way to build paperwork automation into your product.
68
+ </sub>
69
+ </div>
70
+ </a>
71
+ </p>
72
+ </div>
73
+ <br>
74
+ <hr>
75
+ </div>
76
+ <br>
77
+ <br>
78
+
79
+ [![](https://img.shields.io/badge/unicorn-approved-ff69b4.svg)](https://giphy.com/gifs/illustration-rainbow-unicorn-26AHG5KGFxSkUWw1i)
80
+ [![npm dependents](https://badgen.net/npm/dependents/type-fest)](https://www.npmjs.com/package/type-fest?activeTab=dependents)
81
+ [![npm downloads](https://badgen.net/npm/dt/type-fest)](https://www.npmjs.com/package/type-fest)
82
+ [![Docs](https://paka.dev/badges/v0/cute.svg)](https://paka.dev/npm/type-fest)
83
+
84
+ Many of the types here should have been built-in. You can help by suggesting some of them to the [TypeScript project](https://github.com/Microsoft/TypeScript/blob/main/CONTRIBUTING.md).
85
+
86
+ Either add this package as a dependency or copy-paste the needed types. No credit required. 👌
87
+
88
+ PR welcome for additional commonly needed types and docs improvements. Read the [contributing guidelines](.github/contributing.md) first.
89
+
90
+ **Help wanted with reviewing [proposals](https://github.com/sindresorhus/type-fest/issues) and [pull requests](https://github.com/sindresorhus/type-fest/pulls).**
91
+
92
+ ## Install
93
+
94
+ ```sh
95
+ npm install type-fest
96
+ ```
97
+
98
+ *Requires TypeScript >=4.2*
99
+
100
+ ## Usage
101
+
102
+ ```ts
103
+ import type {Except} from 'type-fest';
104
+
105
+ type Foo = {
106
+ unicorn: string;
107
+ rainbow: boolean;
108
+ };
109
+
110
+ type FooWithoutRainbow = Except<Foo, 'rainbow'>;
111
+ //=> {unicorn: string}
112
+ ```
113
+
114
+ ## API
115
+
116
+ Click the type names for complete docs.
117
+
118
+ ### Basic
119
+
120
+ - [`Primitive`](source/primitive.d.ts) - Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
121
+ - [`Class`](source/basic.d.ts) - Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
122
+ - [`Constructor`](source/basic.d.ts) - Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
123
+ - [`TypedArray`](source/typed-array.d.ts) - Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
124
+ - [`ObservableLike`](source/observable-like.d.ts) - Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
125
+
126
+ ### Utilities
127
+
128
+ - [`Except`](source/except.d.ts) - Create a type from an object type without certain keys. This is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys).
129
+ - [`Writable`](source/writable.d.ts) - Create a type that strips `readonly` from all or some of an object's keys. The inverse of `Readonly<T>`. Formerly named `Mutable`.
130
+ - [`Merge`](source/merge.d.ts) - Merge two types into a new type. Keys of the second type overrides keys of the first type.
131
+ - [`MergeExclusive`](source/merge-exclusive.d.ts) - Create a type that has mutually exclusive keys.
132
+ - [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
133
+ - [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly a single key of the given keys and disallows more.
134
+ - [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys.
135
+ - [`RemoveIndexSignature`](source/remove-index-signature.d.ts) - Create a type that only has explicitly defined properties, absent of any index signatures.
136
+ - [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) if you only need one level deep.
137
+ - [`PartialOnUndefinedDeep`](source/partial-on-undefined-deep.d.ts) - Create a deep version of another type where all keys accepting `undefined` type are set to optional.
138
+ - [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of an `object`/`Map`/`Set`/`Array` type. Use [`Readonly<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) if you only need one level deep.
139
+ - [`LiteralUnion`](source/literal-union.d.ts) - Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
140
+ - [`Opaque`](source/opaque.d.ts) - Create an [opaque type](https://codemix.com/opaque-types-in-javascript/).
141
+ - [`UnwrapOpaque`](source/opaque.d.ts) - Revert an [opaque type](https://codemix.com/opaque-types-in-javascript/) back to its original type.
142
+ - [`InvariantOf`](source/invariant-of.d.ts) - Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
143
+ - [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
144
+ - [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
145
+ - [`SetNonNullable`](source/set-non-nullable.d.ts) - Create a type that makes the given keys non-nullable.
146
+ - [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
147
+ - [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
148
+ - [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
149
+ - [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
150
+ - [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
151
+ - [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Convert a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) to the [primitive type](source/primitive.d.ts) it belongs to.
152
+ - [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
153
+ - [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
154
+ - [`Entry`](source/entry.d.ts) - Create a type that represents the type of an entry of a collection.
155
+ - [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
156
+ - [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
157
+ - [`Simplify`](source/simplify.d.ts) - 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.
158
+ - [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
159
+ - [`StringKeyOf`](source/string-key-of.d.ts) - Get keys of the given type as strings.
160
+ - [`Schema`](source/schema.d.ts) - Create a deep version of another object type where property values are recursively replaced into a given value type.
161
+ - [`Exact`](source/exact.d.ts) - Create a type that does not allow extra properties.
162
+ - [`OptionalKeysOf`](source/optional-keys-of.d.ts) - Extract all optional keys from the given type.
163
+ - [`HasOptionalKeys`](source/has-optional-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any optional fields.
164
+ - [`RequiredKeysOf`](source/required-keys-of.d.ts) - Extract all required keys from the given type.
165
+ - [`HasRequiredKeys`](source/has-required-keys.d.ts) - Create a `true`/`false` type depending on whether the given type has any required fields.
166
+ - [`Spread`](source/spread.d.ts) - Mimic the type inferred by TypeScript when merging two objects or two arrays/tuples using the spread syntax.
167
+
168
+ ### JSON
169
+
170
+ - [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
171
+ - [`JsonPrimitive`](source/basic.d.ts) - Matches a JSON primitive.
172
+ - [`JsonObject`](source/basic.d.ts) - Matches a JSON object.
173
+ - [`JsonArray`](source/basic.d.ts) - Matches a JSON array.
174
+ - [`JsonValue`](source/basic.d.ts) - Matches any valid JSON value.
175
+
176
+ ### Async
177
+
178
+ - [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
179
+ - [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
180
+ - [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
181
+
182
+ ### String
183
+
184
+ - [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
185
+ - [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
186
+ - [`Replace`](source/replace.d.ts) - Represents a string with some or all matches replaced by a replacement.
187
+
188
+ ### Array
189
+
190
+ - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
191
+ - [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
192
+ - [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
193
+ - [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
194
+ - [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
195
+ - [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
196
+ - [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length.
197
+
198
+ ### Numeric
199
+
200
+ - [`PositiveInfinity`](source/numeric.d.ts) - Matches the hidden `Infinity` type.
201
+ - [`NegativeInfinity`](source/numeric.d.ts) - Matches the hidden `-Infinity` type.
202
+ - [`Finite`](source/numeric.d.ts) - A finite `number`.
203
+ - [`Integer`](source/numeric.d.ts) - A `number` that is an integer.
204
+ - [`Float`](source/numeric.d.ts) - A `number` that is not an integer.
205
+ - [`NegativeFloat`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is not an integer.
206
+ - [`Negative`](source/numeric.d.ts) - A negative `number`/`bigint` (`-∞ < x < 0`)
207
+ - [`NonNegative`](source/numeric.d.ts) - A non-negative `number`/`bigint` (`0 <= x < ∞`).
208
+ - [`NegativeInteger`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is an integer.
209
+ - [`NonNegativeInteger`](source/numeric.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
210
+
211
+ ### Change case
212
+
213
+ - [`CamelCase`](source/camel-case.d.ts) - Convert a string literal to camel-case (`fooBar`).
214
+ - [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert object properties to camel-case (`fooBar`).
215
+ - [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel-case recursively (`fooBar`).
216
+ - [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case (`foo-bar`).
217
+ - [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert a object properties to kebab-case recursively (`foo-bar`).
218
+ - [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab-case (`foo-bar`).
219
+ - [`PascalCase`](source/pascal-case.d.ts) - Converts a string literal to pascal-case (`FooBar`)
220
+ - [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Converts object properties to pascal-case (`FooBar`)
221
+ - [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Converts object properties to pascal-case (`FooBar`)
222
+ - [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case (`foo_bar`).
223
+ - [`SnakeCasedProperties`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake-case (`foo_bar`).
224
+ - [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake-case recursively (`foo_bar`).
225
+ - [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case (`FOO_BAR`).
226
+ - [`DelimiterCase`](source/delimiter-case.d.ts) - Convert a string literal to a custom string delimiter casing.
227
+ - [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) - Convert object properties to a custom string delimiter casing.
228
+ - [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) - Convert object properties to a custom string delimiter casing recursively.
229
+
230
+ ### Miscellaneous
231
+
232
+ - [`PackageJson`](source/package-json.d.ts) - Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). It also includes support for [TypeScript Declaration Files](https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) and [Yarn Workspaces](https://classic.yarnpkg.com/lang/en/docs/workspaces/).
233
+ - [`TsConfigJson`](source/tsconfig-json.d.ts) - Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 4.4).
234
+
235
+ ## Declined types
236
+
237
+ *If we decline a type addition, we will make sure to document the better solution here.*
238
+
239
+ - [`Diff` and `Spread`](https://github.com/sindresorhus/type-fest/pull/7) - The pull request author didn't provide any real-world use-cases and the PR went stale. If you think this type is useful, provide some real-world use-cases and we might reconsider.
240
+ - [`Dictionary`](https://github.com/sindresorhus/type-fest/issues/33) - You only save a few characters (`Dictionary<number>` vs `Record<string, number>`) from [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type), which is more flexible and well-known. Also, you shouldn't use an object as a dictionary. We have `Map` in JavaScript now.
241
+ - [`ExtractProperties` and `ExtractMethods`](https://github.com/sindresorhus/type-fest/pull/4) - The types violate the single responsibility principle. Instead, refine your types into more granular type hierarchies.
242
+ - [`Url2Json`](https://github.com/sindresorhus/type-fest/pull/262) - Inferring search parameters from a URL string is a cute idea, but not very useful in practice, since search parameters are usually dynamic and defined separately.
243
+ - [`Nullish`](https://github.com/sindresorhus/type-fest/pull/318) - The type only saves a couple of characters, not everyone knows what "nullish" means, and I'm also trying to [get away from `null`](https://github.com/sindresorhus/meta/discussions/7).
244
+ - [`TitleCase`](https://github.com/sindresorhus/type-fest/pull/303) - It's not solving a common need and is a better fit for a separate package.
245
+ - [`ExtendOr` and `ExtendAnd`](https://github.com/sindresorhus/type-fest/pull/247) - The benefits don't outweigh having to learn what they mean.
246
+ - [`PackageJsonExtras`](https://github.com/sindresorhus/type-fest/issues/371) - There are too many possible configurations that can be put into `package.json`. If you would like to extend `PackageJson` to support an additional configuration in your project, please see the *Extending existing types* section below.
247
+
248
+ ## Alternative type names
249
+
250
+ *If you know one of our types by a different name, add it here for discovery.*
251
+
252
+ - `PartialBy` - See [`SetOptional`](https://github.com/sindresorhus/type-fest/blob/main/source/set-optional.d.ts)
253
+ - `RecordDeep`- See [`Schema`](https://github.com/sindresorhus/type-fest/blob/main/source/schema.d.ts)
254
+
255
+ ## Tips
256
+
257
+ ### Extending existing types
258
+
259
+ - [`PackageJson`](source/package-json.d.ts) - There are a lot of tools that place extra configurations inside the `package.json` file. You can extend `PackageJson` to support these additional configurations.
260
+ <details>
261
+ <summary>
262
+ Example
263
+ </summary>
264
+
265
+ [Playground](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBDAnmApnA3gBQIYGMDW2A5igFIDOEAdnNuXAEJ0o4HFmVUC+cAZlBBBwA5ElQBaXinIxhAbgCwAKFCRYCZGnQAZYFRgooPfoJHSANntmKlysWlaESFanAC8jZo-YuaAMgwLKwBhal5gIgB+AC44XX1DADpQqnCiLhsgA)
266
+
267
+ ```ts
268
+ import type {PackageJson as BasePackageJson} from 'type-fest';
269
+ import type {Linter} from 'eslint';
270
+
271
+ type PackageJson = BasePackageJson & {eslintConfig?: Linter.Config};
272
+ ```
273
+ </details>
274
+
275
+ ### Related
276
+
277
+ - [typed-query-selector](https://github.com/g-plane/typed-query-selector) - Enhances `document.querySelector` and `document.querySelectorAll` with a template literal type that matches element types returned from an HTML element query selector.
278
+ - [`Linter.Config`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/eslint/index.d.ts) - Definitions for the [ESLint configuration schema](https://eslint.org/docs/user-guide/configuring/language-options).
279
+
280
+ ### Built-in types
281
+
282
+ There are many advanced types most users don't know about.
283
+
284
+ - [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) - Make all properties in `T` optional.
285
+ <details>
286
+ <summary>
287
+ Example
288
+ </summary>
289
+
290
+ [Playground](https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgHIHsAmEDC6QzADmyA3gLABQyycADnanALYQBcyAzmFKEQNxUaddFDAcQAV2YAjaIMoBfKlQQAbOJ05osEAIIMAQpOBrsUMkOR1eANziRkCfISKSoD4Pg4ZseAsTIALyW1DS0DEysHADkvvoMMQA0VsKi4sgAzAAMuVaKClY2wPaOknSYDrguADwA0sgQAB6QIJjaANYQAJ7oMDp+LsQAfAAUXd0cdUnI9mo+uv6uANp1ALoAlKHhyGAAFsCcAHTOAW4eYF4gyxNrwbNwago0ypRWp66jH8QcAApwYmAjxq8SWIy2FDCNDA3ToKFBQyIdR69wmfQG1TOhShyBgomQX3w3GQE2Q6IA8jIAFYQBBgI4TTiEs5bTQYsFInrLTbbHZOIlgZDlSqQABqj0kKBC3yINx6a2xfOQwH6o2FVXFaklwSCIUkbQghBAEEwENSfNOlykEGefNe5uhB2O6sgS3GPRmLogmslG1tLxUOKgEDA7hAuydtteryAA)
291
+
292
+ ```ts
293
+ interface NodeConfig {
294
+ appName: string;
295
+ port: number;
296
+ }
297
+
298
+ class NodeAppBuilder {
299
+ private configuration: NodeConfig = {
300
+ appName: 'NodeApp',
301
+ port: 3000
302
+ };
303
+
304
+ private updateConfig<Key extends keyof NodeConfig>(key: Key, value: NodeConfig[Key]) {
305
+ this.configuration[key] = value;
306
+ }
307
+
308
+ config(config: Partial<NodeConfig>) {
309
+ type NodeConfigKey = keyof NodeConfig;
310
+
311
+ for (const key of Object.keys(config) as NodeConfigKey[]) {
312
+ const updateValue = config[key];
313
+
314
+ if (updateValue === undefined) {
315
+ continue;
316
+ }
317
+
318
+ this.updateConfig(key, updateValue);
319
+ }
320
+
321
+ return this;
322
+ }
323
+ }
324
+
325
+ // `Partial<NodeConfig>`` allows us to provide only a part of the
326
+ // NodeConfig interface.
327
+ new NodeAppBuilder().config({appName: 'ToDoApp'});
328
+ ```
329
+ </details>
330
+
331
+ - [`Required<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) - Make all properties in `T` required.
332
+ <details>
333
+ <summary>
334
+ Example
335
+ </summary>
336
+
337
+ [Playground](https://typescript-play.js.org/?target=6#code/AQ4SwOwFwUwJwGYEMDGNgGED21VQGJZwC2wA3gFCjXAzFJgA2A-AFzADOUckA5gNxUaIYjA4ckvGG07c+g6gF8KQkAgCuEFFDA5O6gEbEwUbLm2ESwABQIixACJIoSdgCUYAR3Vg4MACYAPGYuFvYAfACU5Ko0APRxwADKMBD+wFAAFuh2Vv7OSBlYGdmc8ABu8LHKsRyGxqY4oQT21pTCIHQMjOwA5DAAHgACxAAOjDAAdChYxL0ANLHUouKSMH0AEmAAhJhY6ozpAJ77GTCMjMCiV0ToSAb7UJPPC9WRgrEJwAAqR6MwSRQPFGUFocDgRHYxnEfGAowh-zgUCOwF6KwkUl6tXqJhCeEsxDaS1AXSYfUGI3GUxmc0WSneQA)
338
+
339
+ ```ts
340
+ interface ContactForm {
341
+ email?: string;
342
+ message?: string;
343
+ }
344
+
345
+ function submitContactForm(formData: Required<ContactForm>) {
346
+ // Send the form data to the server.
347
+ }
348
+
349
+ submitContactForm({
350
+ email: 'ex@mple.com',
351
+ message: 'Hi! Could you tell me more about…',
352
+ });
353
+
354
+ // TypeScript error: missing property 'message'
355
+ submitContactForm({
356
+ email: 'ex@mple.com',
357
+ });
358
+ ```
359
+ </details>
360
+
361
+ - [`Readonly<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) - Make all properties in `T` readonly.
362
+ <details>
363
+ <summary>
364
+ Example
365
+ </summary>
366
+
367
+ [Playground](https://typescript-play.js.org/?target=6#code/AQ4UwOwVwW2AZA9gc3mAbmANsA3gKFCOAHkAzMgGkOJABEwAjKZa2kAUQCcvEu32AMQCGAF2FYBIAL4BufDRABLCKLBcywgMZgEKZOoDCiCGSXI8i4hGEwwALmABnUVxXJ57YFgzZHSVF8sT1BpBSItLGEnJz1kAy5LLy0TM2RHACUwYQATEywATwAeAITjU3MAPnkrCJMXLigtUT4AClxgGztKbyDgaX99I1TzAEokr1BRAAslJwA6FIqLAF48TtswHp9MHDla9hJGACswZvmyLjAwAC8wVpm5xZHkUZDaMKIwqyWXYCW0oN4sNlsA1h0ug5gAByACyBQAggAHJHQ7ZBIFoXbzBjMCz7OoQP5YIaJNYQMAAdziCVaALGNSIAHomcAACoFJFgADKWjcSNEwG4vC4ji0wggEEQguiTnMEGALWAV1yAFp8gVgEjeFyuKICvMrCTgVxnst5jtsGC4ljsPNhXxGaAWcAAOq6YRXYDCRg+RWIcA5JSC+kWdCepQ+v3RYCU3RInzRMCGwlpC19NYBW1Ye08R1AA)
368
+
369
+ ```ts
370
+ enum LogLevel {
371
+ Off,
372
+ Debug,
373
+ Error,
374
+ Fatal
375
+ };
376
+
377
+ interface LoggerConfig {
378
+ name: string;
379
+ level: LogLevel;
380
+ }
381
+
382
+ class Logger {
383
+ config: Readonly<LoggerConfig>;
384
+
385
+ constructor({name, level}: LoggerConfig) {
386
+ this.config = {name, level};
387
+ Object.freeze(this.config);
388
+ }
389
+ }
390
+
391
+ const config: LoggerConfig = {
392
+ name: 'MyApp',
393
+ level: LogLevel.Debug
394
+ };
395
+
396
+ const logger = new Logger(config);
397
+
398
+ // TypeScript Error: cannot assign to read-only property.
399
+ logger.config.level = LogLevel.Error;
400
+
401
+ // We are able to edit config variable as we please.
402
+ config.level = LogLevel.Error;
403
+ ```
404
+ </details>
405
+
406
+ - [`Pick<T, K>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys) - From `T`, pick a set of properties whose keys are in the union `K`.
407
+ <details>
408
+ <summary>
409
+ Example
410
+ </summary>
411
+
412
+ [Playground](https://typescript-play.js.org/?target=6#code/AQ4SwOwFwUwJwGYEMDGNgEE5TCgNugN4BQoZwOUBAXMAM5RyQDmA3KeSFABYCuAtgCMISMHloMmENh04oA9tBjQJjFuzIBfYrOAB6PcADCcGElh1gEGAHcKATwAO6ebyjB5CTNlwFwSxFR0BX5HeToYABNgBDh5fm8cfBg6AHIKG3ldA2BHOOcfFNpUygJ0pAhokr4hETFUgDpswywkggAFUwA3MFtgAF5gQgowKhhVKTYKGuFRcXo1aVZgbTIoJ3RW3xhOmB6+wfbcAGsAHi3kgBpgEtGy4AAfG54BWfqAPnZm4AAlZUj4MAkMA8GAGB4vEgfMlLLw6CwPBA8PYRmMgZVgAC6CgmI4cIommQELwICh8RBgKZKvALh1ur0bHQABR5PYMui0Wk7em2ADaAF0AJS0AASABUALIAGQAogR+Mp3CROCAFBBwVC2ikBpj5CgBIqGjizLA5TAFdAmalImAuqlBRoVQh5HBgEy1eDWfs7J5cjzGYKhroVfpDEhHM4MV6GRR5NN0JrtnRg6BVirTFBeHAKYmYY6QNpdB73LmCJZBlSAXAubtvczeSmQMNSuMbmKNgBlHFgPEUNwusBIPAAQlS1xetTmxT0SDoESgdD0C4aACtHMwxytLrohawgA)
413
+
414
+ ```ts
415
+ interface Article {
416
+ title: string;
417
+ thumbnail: string;
418
+ content: string;
419
+ }
420
+
421
+ // Creates new type out of the `Article` interface composed
422
+ // from the Articles' two properties: `title` and `thumbnail`.
423
+ // `ArticlePreview = {title: string; thumbnail: string}`
424
+ type ArticlePreview = Pick<Article, 'title' | 'thumbnail'>;
425
+
426
+ // Render a list of articles using only title and description.
427
+ function renderArticlePreviews(previews: ArticlePreview[]): HTMLElement {
428
+ const articles = document.createElement('div');
429
+
430
+ for (const preview of previews) {
431
+ // Append preview to the articles.
432
+ }
433
+
434
+ return articles;
435
+ }
436
+
437
+ const articles = renderArticlePreviews([
438
+ {
439
+ title: 'TypeScript tutorial!',
440
+ thumbnail: '/assets/ts.jpg'
441
+ }
442
+ ]);
443
+ ```
444
+ </details>
445
+
446
+ - [`Record<K, T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type) - Construct a type with a set of properties `K` of type `T`.
447
+ <details>
448
+ <summary>
449
+ Example
450
+ </summary>
451
+
452
+ [Playground](https://typescript-play.js.org/?target=6#code/AQ4ejYAUHsGcCWAXBMB2dgwGbAKYC2ADgDYwCeeemCaWArgE7ADGMxAhmuQHQBQoYEnJE8wALKEARnkaxEKdMAC8wAOS0kstGuAAfdQBM8ANzxlRjXQbVaWACwC0JPB0NqA3HwGgIwAJJoWozYHCxixnAsjAhStADmwESMMJYo1Fi4HMCIaPEu+MRklHj8gpqyoeHAAKJFFFTAAN4+giDYCIxwSAByHAR4AFw5SDF5Xm2gJBzdfQPD3WPxE5PAlBxdAPLYNQAelgh4aOHDaPQEMowrIAC+3oJ+AMKMrlrAXFhSAFZ4LEhC9g4-0BmA4JBISXgiCkBQABpILrJ5MhUGhYcATGD6Bk4Hh-jNgABrPDkOBlXyQAAq9ngYmJpOAAHcEOCRjAXqwYODfoo6DhakUSph+Uh7GI4P0xER4Cj0OSQGwMP8tP1hgAlX7swwAHgRl2RvIANALSA08ABtAC6AD4VM1Wm0Kow0MMrYaHYJjGYLLJXZb3at1HYnC43Go-QHQDcvA6-JsmEJXARgCDgMYWAhjIYhDAU+YiMAAFIwex0ZmilMITCGF79TLAGRsAgJYAAZRwSEZGzEABFTOZUrJ5Yn+jwnWgeER6HB7AAKJrADpdXqS4ZqYultTG6azVfqHswPBbtauLY7fayQ7HIbAAAMwBuAEoYw9IBq2Ixs9h2eFMOQYPQObALQKJgggABeYhghCIpikkKRpOQRIknAsZUiIeCttECBEP8NSMCkjDDAARMGziuIYxHwYOjDCMBmDNnAuTxA6irdCOBB1Lh5Dqpqn66tISIykawBnOCtqqC0gbjqc9DgpGkxegOliyfJDrRkAA)
453
+
454
+ ```ts
455
+ // Positions of employees in our company.
456
+ type MemberPosition = 'intern' | 'developer' | 'tech-lead';
457
+
458
+ // Interface describing properties of a single employee.
459
+ interface Employee {
460
+ firstName: string;
461
+ lastName: string;
462
+ yearsOfExperience: number;
463
+ }
464
+
465
+ // Create an object that has all possible `MemberPosition` values set as keys.
466
+ // Those keys will store a collection of Employees of the same position.
467
+ const team: Record<MemberPosition, Employee[]> = {
468
+ intern: [],
469
+ developer: [],
470
+ 'tech-lead': [],
471
+ };
472
+
473
+ // Our team has decided to help John with his dream of becoming Software Developer.
474
+ team.intern.push({
475
+ firstName: 'John',
476
+ lastName: 'Doe',
477
+ yearsOfExperience: 0
478
+ });
479
+
480
+ // `Record` forces you to initialize all of the property keys.
481
+ // TypeScript Error: "tech-lead" property is missing
482
+ const teamEmpty: Record<MemberPosition, null> = {
483
+ intern: null,
484
+ developer: null,
485
+ };
486
+ ```
487
+ </details>
488
+
489
+ - [`Exclude<T, U>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#excludetype-excludedunion) - Exclude from `T` those types that are assignable to `U`.
490
+ <details>
491
+ <summary>
492
+ Example
493
+ </summary>
494
+
495
+ [Playground](https://typescript-play.js.org/?target=6#code/JYOwLgpgTgZghgYwgAgMrQG7QMIHsQzADmyA3gFDLIAOuUYAXMiAK4A2byAPsgM5hRQJHqwC2AI2gBucgF9y5MAE9qKAEoQAjiwj8AEnBAATNtGQBeZAAooWphu26wAGmS3e93bRC8IASgsAPmRDJRlyAHoI5ABRAA8ENhYjFFYOZGVVZBgoXFFkAAM0zh5+QRBhZhYJaAKAOkjogEkQZAQ4X2QAdwALCFbaemRgXmQtFjhOMFwq9K6ULuB0lk6U+HYwZAxJnQaYFhAEMGB8ZCIIMAAFOjAANR2IK0HGWISklIAedCgsKDwCYgAbQA5M9gQBdVzFQJ+JhiSRQMiUYYwayZCC4VHPCzmSzAspCYEBWxgFhQAZwKC+FpgJ43VwARgADH4ZFQSWSBjcZPJyPtDsdTvxKWBvr8rD1DCZoJ5HPopaYoK4EPhCEQmGKcKriLCtrhgEYkVQVT5Nr4fmZLLZtMBbFZgT0wGBqES6ghbHBIJqoBKFdBWQpjfh+DQbhY2tqiHVsbjLMVkAB+ZAAZiZaeQTHOVxu9ySjxNaujNwDVHNvzqbBGkBAdPoAfkQA)
496
+
497
+ ```ts
498
+ interface ServerConfig {
499
+ port: null | string | number;
500
+ }
501
+
502
+ type RequestHandler = (request: Request, response: Response) => void;
503
+
504
+ // Exclude `null` type from `null | string | number`.
505
+ // In case the port is equal to `null`, we will use default value.
506
+ function getPortValue(port: Exclude<ServerConfig['port'], null>): number {
507
+ if (typeof port === 'string') {
508
+ return parseInt(port, 10);
509
+ }
510
+
511
+ return port;
512
+ }
513
+
514
+ function startServer(handler: RequestHandler, config: ServerConfig): void {
515
+ const server = require('http').createServer(handler);
516
+
517
+ const port = config.port === null ? 3000 : getPortValue(config.port);
518
+ server.listen(port);
519
+ }
520
+ ```
521
+ </details>
522
+
523
+ - [`Extract<T, U>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttype-union) - Extract from `T` those types that are assignable to `U`.
524
+ <details>
525
+ <summary>
526
+ Example
527
+ </summary>
528
+
529
+ [Playground](https://typescript-play.js.org/?target=6#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXzSwEdkQBJYACgEoAueVZAWwCMQYBuAKDDwGcM8MgBF4AXngBlAJ6scESgHIRi6ty5ZUGdoihgEABXZ888AN5d48ANoiAuvUat23K6ihMQ9ATE0BzV3goPy8GZjZOLgBfLi4Aejj4AEEICBwAdz54MAALKFQQ+BxEeAAHY1NgKAwoIKy0grr4DByEUpgccpgMaXgAaxBerCzi+B9-ZulygDouFHRsU1z8kKMYE1RhaqgAHkt4AHkWACt4EAAPbVRgLLWNgBp9gGlBs8uQa6yAUUuYPQwdgNpKM7nh7mMML4CgA+R5WABqUAgpDeVxuhxO1he0jsXGh8EoOBO9COx3BQPo2PBADckaR6IjkSA6PBqTgsMBzPsicdrEC7OJWXSQNwYvFEgAVTS9JLXODpeDpKBZFg4GCoWa8VACIJykAKiQWKy2YQOAioYikCg0OEMDyhRSy4DyxS24KhAAMjyi6gS8AAwjh5OD0iBFHAkJoEOksC1mnkMJq8gUQKDNttKPlnfrwYp3J5XfBHXqoKpfYkAOI4ansTxaeDADmoRSCCBYAbxhC6TDx6rwYHIRX5bScjA4bLJwoDmDwDkfbA9JMrVMVdM1TN69LgkTgwgkchUahqIA)
530
+
531
+ ```ts
532
+ declare function uniqueId(): number;
533
+
534
+ const ID = Symbol('ID');
535
+
536
+ interface Person {
537
+ [ID]: number;
538
+ name: string;
539
+ age: number;
540
+ }
541
+
542
+ // Allows changing the person data as long as the property key is of string type.
543
+ function changePersonData<
544
+ Obj extends Person,
545
+ Key extends Extract<keyof Person, string>,
546
+ Value extends Obj[Key]
547
+ > (obj: Obj, key: Key, value: Value): void {
548
+ obj[key] = value;
549
+ }
550
+
551
+ // Tiny Andrew was born.
552
+ const andrew = {
553
+ [ID]: uniqueId(),
554
+ name: 'Andrew',
555
+ age: 0,
556
+ };
557
+
558
+ // Cool, we're fine with that.
559
+ changePersonData(andrew, 'name', 'Pony');
560
+
561
+ // Goverment didn't like the fact that you wanted to change your identity.
562
+ changePersonData(andrew, ID, uniqueId());
563
+ ```
564
+ </details>
565
+
566
+ - [`NonNullable<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype) - Exclude `null` and `undefined` from `T`.
567
+ <details>
568
+ <summary>
569
+ Example
570
+ </summary>
571
+ Works with <a href="https://www.typescriptlang.org/tsconfig#strictNullChecks"><code>strictNullChecks</code></a> set to <code>true</code>.
572
+
573
+ [Playground](https://typescript-play.js.org/?target=6#code/C4TwDgpgBACg9gJ2AOQK4FsBGEFQLxQDOwCAlgHYDmUAPlORtrnQwDasDcAUFwPQBU-WAEMkUOADMowqAGNWwwoSgATCBIqlgpOOSjAAFsOBRSy1IQgr9cKJlSlW1mZYQA3HFH68u8xcoBlHA8EACEHJ08Aby4oKDBUTFZSWXjEFEYcAEIALihkXTR2YSSIAB54JDQsHAA+blj4xOTUsHSACkMzPKD3HHDHNQQAGjSkPMqMmoQASh7g-oihqBi4uNIpdraxPAI2VhmVxrX9AzMAOm2ppnwoAA4ABifuE4BfKAhWSyOTuK7CS7pao3AhXF5rV48E4ICDAVAIPT-cGQyG+XTEIgLMJLTx7CAAdygvRCA0iCHaMwarhJOIQjUBSHaACJHk8mYdeLwxtdcVAAOSsh58+lXdr7Dlcq7A3n3J4PEUdADMcspUE53OluAIUGVTx46oAKuAIAFZGQwCYAKIIBCILjUxaDHAMnla+iodjcIA)
574
+
575
+ ```ts
576
+ type PortNumber = string | number | null;
577
+
578
+ /** Part of a class definition that is used to build a server */
579
+ class ServerBuilder {
580
+ portNumber!: NonNullable<PortNumber>;
581
+
582
+ port(this: ServerBuilder, port: PortNumber): ServerBuilder {
583
+ if (port == null) {
584
+ this.portNumber = 8000;
585
+ } else {
586
+ this.portNumber = port;
587
+ }
588
+
589
+ return this;
590
+ }
591
+ }
592
+
593
+ const serverBuilder = new ServerBuilder();
594
+
595
+ serverBuilder
596
+ .port('8000') // portNumber = '8000'
597
+ .port(null) // portNumber = 8000
598
+ .port(3000); // portNumber = 3000
599
+
600
+ // TypeScript error
601
+ serverBuilder.portNumber = null;
602
+ ```
603
+ </details>
604
+
605
+ - [`Parameters<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype) - Obtain the parameters of a function type in a tuple.
606
+ <details>
607
+ <summary>
608
+ Example
609
+ </summary>
610
+
611
+ [Playground](https://typescript-play.js.org/?target=6#code/GYVwdgxgLglg9mABAZwBYmMANgUwBQxgAOIUAXIgIZgCeA2gLoCUFAbnDACaIDeAUIkQB6IYgCypSlBxUATrMo1ECsJzgBbLEoipqAc0J7EMKMgDkiHLnU4wp46pwAPHMgB0fAL58+oSLARECEosLAA5ABUYG2QAHgAxJGdpVWREPDdMylk9ZApqemZEAF4APipacrw-CApEgBogkKwAYThwckQwEHUAIxxZJl4BYVEImiIZKF0oZRwiWVdbeygJmThgOYgcGFYcbhqApCJsyhtpWXcR1cnEePBoeDAABVPzgbTixFeFd8uEsClADcIxGiygIFkSEOT3SmTc2VydQeRx+ZxwF2QQ34gkEwDgsnSuFmMBKiAADEDjIhYk1Qm0OlSYABqZnYka4xA1DJZHJYkGc7yCbyeRA+CAIZCzNAYbA4CIAdxg2zJwVCkWirjwMswuEaACYmCCgA)
612
+
613
+ ```ts
614
+ function shuffle(input: any[]): void {
615
+ // Mutate array randomly changing its' elements indexes.
616
+ }
617
+
618
+ function callNTimes<Fn extends (...args: any[]) => any> (func: Fn, callCount: number) {
619
+ // Type that represents the type of the received function parameters.
620
+ type FunctionParameters = Parameters<Fn>;
621
+
622
+ return function (...args: FunctionParameters) {
623
+ for (let i = 0; i < callCount; i++) {
624
+ func(...args);
625
+ }
626
+ }
627
+ }
628
+
629
+ const shuffleTwice = callNTimes(shuffle, 2);
630
+ ```
631
+ </details>
632
+
633
+ - [`ConstructorParameters<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype) - Obtain the parameters of a constructor function type in a tuple.
634
+ <details>
635
+ <summary>
636
+ Example
637
+ </summary>
638
+
639
+ [Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECCBOAXAlqApgWQPYBM0mgG8AoaaFRENALmgkXmQDsBzAblOmCycTV4D8teo1YdO3JiICuwRFngAKClWENmLAJRFOZRAAtkEAHQq00ALzlklNBzIBfYk+KhIMAJJTEYJsDQAwmDA+mgAPAAq0GgAHnxMODCKTGgA7tCKxllg8CwQtL4AngDaALraFgB80EWa1SRkAA6MAG5gfNAB4FABPDJyCrQR9tDNyG0dwMGhtBhgjWEiGgA00F70vv4RhY3hEZXVVinpc42KmuJkkv3y8Bly8EPaDWTkhiZd7r3e8LK3llwGCMXGQWGhEOsfH5zJlsrl8p0+gw-goAAo5MAAW3BaHgEEilU0tEhmzQ212BJ0ry4SOg+kg+gBBiMximIGA0nAfAQLGk2N4EAAEgzYcYcnkLsRdDTvNEYkYUKwSdCme9WdM0MYwYhFPSIPpJdTkAAzDKxBUaZX+aAAQgsVmkCTQxuYaBw2ng4Ok8CYcotSu8pMur09iG9vuObxZnx6SN+AyUWTF8MN0CcZE4Ywm5jZHK5aB5fP4iCFIqT4oRRTKRLo6lYVNeAHpG50wOzOe1zHr9NLQ+HoABybsD4HOKXXRA1JCoKhBELmI5pNaB6Fz0KKBAodDYPAgSUTmqYsAALx4m5nC6nW9nGq14KtaEUA9gR9PvuNCjQ9BgACNvcwNBtAcLiAA)
640
+
641
+ ```ts
642
+ class ArticleModel {
643
+ title: string;
644
+ content?: string;
645
+
646
+ constructor(title: string) {
647
+ this.title = title;
648
+ }
649
+ }
650
+
651
+ class InstanceCache<T extends (new (...args: any[]) => any)> {
652
+ private ClassConstructor: T;
653
+ private cache: Map<string, InstanceType<T>> = new Map();
654
+
655
+ constructor (ctr: T) {
656
+ this.ClassConstructor = ctr;
657
+ }
658
+
659
+ getInstance (...args: ConstructorParameters<T>): InstanceType<T> {
660
+ const hash = this.calculateArgumentsHash(...args);
661
+
662
+ const existingInstance = this.cache.get(hash);
663
+ if (existingInstance !== undefined) {
664
+ return existingInstance;
665
+ }
666
+
667
+ return new this.ClassConstructor(...args);
668
+ }
669
+
670
+ private calculateArgumentsHash(...args: any[]): string {
671
+ // Calculate hash.
672
+ return 'hash';
673
+ }
674
+ }
675
+
676
+ const articleCache = new InstanceCache(ArticleModel);
677
+ const amazonArticle = articleCache.getInstance('Amazon forests burining!');
678
+ ```
679
+ </details>
680
+
681
+ - [`ReturnType<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) - Obtain the return type of a function type.
682
+ <details>
683
+ <summary>
684
+ Example
685
+ </summary>
686
+
687
+ [Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECSAmICmBlJAnAbgS2E6A3gFDTTwD2AcuQC4AW2AdgOYAUAlAFzSbnbyEAvkWFFQkGJSQB3GMVI1sNZNwg10TZgG4S0YOUY0kh1es07d+xmvQBXYDXLpWi5UlMaWAGj0GjJ6BtNdkJdBQYIADpXZGgAXmgYpB1ScOwoq38aeN9DYxoU6GFRKzVoJjUwRjwAYXJbPPRuAFkwAAcAHgAxBodsAx9GWwBbACMMAD4cxhloVraOCyYjdAAzMDxoOut1e0d0UNIZ6WhWSPOwdGYIbiqATwBtAF0uaHudUQB6ACpv6ABpJBINqJdAbADW0Do5BOw3u5R2VTwMHIq2gAANtjZ0bkbHsnFCwJh8ONjHp0EgwEZ4JFoN9PkRVr1FAZoMwkDRYIjqkgOrosepoEgAB7+eAwAV2BxOLy6ACCVxgIrFEoMeOl6AACpcwMMORgIB1JRMiBNWKVdhruJKfOdIpdrtwFddXlzKjyACp3Nq842HaDIbL6BrZBIVGhIpB1EMYSLsmjmtWW-YhAA+qegAAYLKQLQj3ZsEsdccmnGcLor2Dn8xGedHGpEIBzEzspfsfMHDNAANTQACMVaIljV5GQkRA5DYmIpVKQAgAJARO9le33BDXIyi0YuLW2nJFGLqkOvxFB0YPdBSaLZ0IwNzyPkO8-xkGgsLh8Al427a3hWAhXwwHA8EHT5PmgAB1bAQBAANJ24adKWpft72RaBUTgRBUCAj89HAM8xCTaBjggABRQx0DuHJv25P9dCkWRZVIAAiBjoFImpmjlFBgA0NpsjadByDacgIDAEAIAAQmYpjoGYgAZSBsmGPw6DtZiiFA8CoJguDmAQmoZ2QvtUKQLdoAYmBTwgdEiCAA)
688
+
689
+ ```ts
690
+ /** Provides every element of the iterable `iter` into the `callback` function and stores the results in an array. */
691
+ function mapIter<
692
+ Elem,
693
+ Func extends (elem: Elem) => any,
694
+ Ret extends ReturnType<Func>
695
+ >(iter: Iterable<Elem>, callback: Func): Ret[] {
696
+ const mapped: Ret[] = [];
697
+
698
+ for (const elem of iter) {
699
+ mapped.push(callback(elem));
700
+ }
701
+
702
+ return mapped;
703
+ }
704
+
705
+ const setObject: Set<string> = new Set();
706
+ const mapObject: Map<number, string> = new Map();
707
+
708
+ mapIter(setObject, (value: string) => value.indexOf('Foo')); // number[]
709
+
710
+ mapIter(mapObject, ([key, value]: [number, string]) => {
711
+ return key % 2 === 0 ? value : 'Odd';
712
+ }); // string[]
713
+ ```
714
+ </details>
715
+
716
+ - [`InstanceType<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype) - Obtain the instance type of a constructor function type.
717
+ <details>
718
+ <summary>
719
+ Example
720
+ </summary>
721
+
722
+ [Playground](https://typescript-play.js.org/?target=6#code/MYGwhgzhAECSAmICmBlJAnAbgS2E6A3gFDTTwD2AcuQC4AW2AdgOYAUAlAFzSbnbyEAvkWFFQkGJSQB3GMVI1sNZNwg10TZgG4S0YOUY0kh1es07d+xmvQBXYDXLpWi5UlMaWAGj0GjJ6BtNdkJdBQYIADpXZGgAXmgYpB1ScOwoq38aeN9DYxoU6GFRKzVoJjUwRjwAYXJbPPRuAFkwAAcAHgAxBodsAx9GWwBbACMMAD4cxhloVraOCyYjdAAzMDxoOut1e0d0UNIZ6WhWSPOwdGYIbiqATwBtAF0uaHudUQB6ACpv6ABpJBINqJdAbADW0Do5BOw3u5R2VTwMHIq2gAANtjZ0bkbHsnFCwJh8ONjHp0EgwEZ4JFoN9PkRVr1FAZoMwkDRYIjqkgOrosepoEgAB7+eAwAV2BxOLy6ACCVxgIrFEoMeOl6AACpcwMMORgIB1JRMiBNWKVdhruJKfOdIpdrtwFddXlzKjyACp3Nq842HaDIbL6BrZBIVGhIpB1EMYSLsmjmtWW-YhAA+qegAAYLKQLQj3ZsEsdccmnGcLor2Dn8xGedHGpEIBzEzspfsfMHDNAANTQACMVaIljV5GQkRA5DYmIpVKQAgAJARO9le33BDXIyi0YuLW2nJFGLqkOvxFB0YPdBSaLZ0IwNzyPkO8-xkGgsLh8Al427a3hWAhXwwHA8EHT5PmgAB1bAQBAANJ24adKWpft72RaBUTgRBUCAj89HAM8xCTaBjggABRQx0DuHJv25P9dCkWRZVIAAiBjoFImpmjlFBgA0NpsjadByDacgIDAEAIAAQmYpjoGYgAZSBsmGPw6DtZiiFA8CoJguDmAQmoZ2QvtUKQLdoAYmBTwgdEiCAA)
723
+
724
+ ```ts
725
+ class IdleService {
726
+ doNothing (): void {}
727
+ }
728
+
729
+ class News {
730
+ title: string;
731
+ content: string;
732
+
733
+ constructor(title: string, content: string) {
734
+ this.title = title;
735
+ this.content = content;
736
+ }
737
+ }
738
+
739
+ const instanceCounter: Map<Function, number> = new Map();
740
+
741
+ interface Constructor {
742
+ new(...args: any[]): any;
743
+ }
744
+
745
+ // Keep track how many instances of `Constr` constructor have been created.
746
+ function getInstance<
747
+ Constr extends Constructor,
748
+ Args extends ConstructorParameters<Constr>
749
+ >(constructor: Constr, ...args: Args): InstanceType<Constr> {
750
+ let count = instanceCounter.get(constructor) || 0;
751
+
752
+ const instance = new constructor(...args);
753
+
754
+ instanceCounter.set(constructor, count + 1);
755
+
756
+ console.log(`Created ${count + 1} instances of ${Constr.name} class`);
757
+
758
+ return instance;
759
+ }
760
+
761
+
762
+ const idleService = getInstance(IdleService);
763
+ // Will log: `Created 1 instances of IdleService class`
764
+ const newsEntry = getInstance(News, 'New ECMAScript proposals!', 'Last month...');
765
+ // Will log: `Created 1 instances of News class`
766
+ ```
767
+ </details>
768
+
769
+ - [`Omit<T, K>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys) - Constructs a type by picking all properties from T and then removing K.
770
+ <details>
771
+ <summary>
772
+ Example
773
+ </summary>
774
+
775
+ [Playground](https://typescript-play.js.org/?target=6#code/JYOwLgpgTgZghgYwgAgIImAWzgG2QbwChlks4BzCAVShwC5kBnMKUcgbmKYAcIFgIjBs1YgOXMpSFMWbANoBdTiW5woFddwAW0kfKWEAvoUIB6U8gDCUCHEiNkICAHdkYAJ69kz4GC3JcPG4oAHteKDABBxCYNAxsPFBIWEQUCAAPJG4wZABySUFcgJAAEzMLXNV1ck0dIuCw6EjBADpy5AB1FAQ4EGQAV0YUP2AHDy8wEOQbUugmBLwtEIA3OcmQnEjuZBgQqE7gAGtgZAhwKHdkHFGwNvGUdDIcAGUliIBJEF3kAF5kAHlML4ADyPBIAGjyBUYRQAPnkqho4NoYQA+TiEGD9EAISIhPozErQMG4AASK2gn2+AApek9pCSXm8wFSQooAJQMUkAFQAsgAZACiOAgmDOOSIJAQ+OYyGl4DgoDmf2QJRCCH6YvALQQNjsEGFovF1NyJWAy1y7OUyHMyE+yRAuFImG4Iq1YDswHxbRINjA-SgfXlHqVUE4xiAA)
776
+
777
+ ```ts
778
+ interface Animal {
779
+ imageUrl: string;
780
+ species: string;
781
+ images: string[];
782
+ paragraphs: string[];
783
+ }
784
+
785
+ // Creates new type with all properties of the `Animal` interface
786
+ // except 'images' and 'paragraphs' properties. We can use this
787
+ // type to render small hover tooltip for a wiki entry list.
788
+ type AnimalShortInfo = Omit<Animal, 'images' | 'paragraphs'>;
789
+
790
+ function renderAnimalHoverInfo (animals: AnimalShortInfo[]): HTMLElement {
791
+ const container = document.createElement('div');
792
+ // Internal implementation.
793
+ return container;
794
+ }
795
+ ```
796
+ </details>
797
+
798
+ - [`Uppercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#uppercasestringtype) - Transforms every character in a string into uppercase.
799
+ <details>
800
+ <summary>
801
+ Example
802
+ </summary>
803
+
804
+ ```ts
805
+ type T = Uppercase<'hello'>; // 'HELLO'
806
+
807
+ type T2 = Uppercase<'foo' | 'bar'>; // 'FOO' | 'BAR'
808
+
809
+ type T3<S extends string> = Uppercase<`aB${S}`>;
810
+ type T4 = T3<'xYz'>; // 'ABXYZ'
811
+
812
+ type T5 = Uppercase<string>; // string
813
+ type T6 = Uppercase<any>; // any
814
+ type T7 = Uppercase<never>; // never
815
+ type T8 = Uppercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
816
+ ```
817
+ </details>
818
+
819
+ - [`Lowercase<S extends string>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#lowercasestringtype) - Transforms every character in a string into lowercase.
820
+ <details>
821
+ <summary>
822
+ Example
823
+ </summary>
824
+
825
+ ```ts
826
+ type T = Lowercase<'HELLO'>; // 'hello'
827
+
828
+ type T2 = Lowercase<'FOO' | 'BAR'>; // 'foo' | 'bar'
829
+
830
+ type T3<S extends string> = Lowercase<`aB${S}`>;
831
+ type T4 = T3<'xYz'>; // 'abxyz'
832
+
833
+ type T5 = Lowercase<string>; // string
834
+ type T6 = Lowercase<any>; // any
835
+ type T7 = Lowercase<never>; // never
836
+ type T8 = Lowercase<42>; // Error, type 'number' does not satisfy the constraint 'string'
837
+ ```
838
+ </details>
839
+
840
+ - [`Capitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#capitalizestringtype) - Transforms the first character in a string into uppercase.
841
+ <details>
842
+ <summary>
843
+ Example
844
+ </summary>
845
+
846
+ ```ts
847
+ type T = Capitalize<'hello'>; // 'Hello'
848
+
849
+ type T2 = Capitalize<'foo' | 'bar'>; // 'Foo' | 'Bar'
850
+
851
+ type T3<S extends string> = Capitalize<`aB${S}`>;
852
+ type T4 = T3<'xYz'>; // 'ABxYz'
853
+
854
+ type T5 = Capitalize<string>; // string
855
+ type T6 = Capitalize<any>; // any
856
+ type T7 = Capitalize<never>; // never
857
+ type T8 = Capitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
858
+ ```
859
+ </details>
860
+
861
+ - [`Uncapitalize<S extends string>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#uncapitalizestringtype) - Transforms the first character in a string into lowercase.
862
+ <details>
863
+ <summary>
864
+ Example
865
+ </summary>
866
+
867
+ ```ts
868
+ type T = Uncapitalize<'Hello'>; // 'hello'
869
+
870
+ type T2 = Uncapitalize<'Foo' | 'Bar'>; // 'foo' | 'bar'
871
+
872
+ type T3<S extends string> = Uncapitalize<`AB${S}`>;
873
+ type T4 = T3<'xYz'>; // 'aBxYz'
874
+
875
+ type T5 = Uncapitalize<string>; // string
876
+ type T6 = Uncapitalize<any>; // any
877
+ type T7 = Uncapitalize<never>; // never
878
+ type T8 = Uncapitalize<42>; // Error, type 'number' does not satisfy the constraint 'string'
879
+ ```
880
+ </details>
881
+
882
+ You can find some examples in the [TypeScript docs](https://www.typescriptlang.org/docs/handbook/utility-types.html).
883
+
884
+ ## Maintainers
885
+
886
+ - [Sindre Sorhus](https://github.com/sindresorhus)
887
+ - [Jarek Radosz](https://github.com/CvX)
888
+ - [Dimitri Benin](https://github.com/BendingBender)
889
+ - [Pelle Wessman](https://github.com/voxpelli)
890
+
891
+ ## License
892
+
893
+ SPDX-License-Identifier: (MIT OR CC0-1.0)
894
+
895
+ ---
896
+
897
+ <div align="center">
898
+ <b>
899
+ <a href="https://tidelift.com/subscription/pkg/npm-type-fest?utm_source=npm-type-fest&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
900
+ </b>
901
+ <br>
902
+ <sub>
903
+ Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
904
+ </sub>
905
+ </div>