type-fest 5.0.1 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/index.d.ts +9 -0
  2. package/package.json +4 -1
  3. package/readme.md +21 -11
  4. package/source/all-extend.d.ts +3 -1
  5. package/source/all-union-fields.d.ts +3 -1
  6. package/source/and.d.ts +4 -0
  7. package/source/array-element.d.ts +46 -0
  8. package/source/array-indices.d.ts +2 -0
  9. package/source/array-slice.d.ts +2 -0
  10. package/source/array-splice.d.ts +7 -4
  11. package/source/array-tail.d.ts +3 -1
  12. package/source/array-values.d.ts +2 -0
  13. package/source/arrayable.d.ts +3 -1
  14. package/source/async-return-type.d.ts +2 -0
  15. package/source/asyncify.d.ts +2 -0
  16. package/source/basic.d.ts +2 -0
  17. package/source/camel-case.d.ts +8 -5
  18. package/source/camel-cased-properties-deep.d.ts +6 -4
  19. package/source/camel-cased-properties.d.ts +6 -4
  20. package/source/characters.d.ts +2 -0
  21. package/source/conditional-except.d.ts +2 -0
  22. package/source/conditional-keys.d.ts +2 -0
  23. package/source/conditional-pick-deep.d.ts +4 -2
  24. package/source/conditional-pick.d.ts +2 -0
  25. package/source/conditional-simplify-deep.d.ts +3 -1
  26. package/source/conditional-simplify.d.ts +3 -1
  27. package/source/delimiter-case.d.ts +7 -5
  28. package/source/delimiter-cased-properties-deep.d.ts +6 -4
  29. package/source/delimiter-cased-properties.d.ts +6 -4
  30. package/source/distributed-omit.d.ts +2 -0
  31. package/source/distributed-pick.d.ts +2 -0
  32. package/source/empty-object.d.ts +3 -1
  33. package/source/entries.d.ts +7 -5
  34. package/source/entry.d.ts +10 -8
  35. package/source/exact.d.ts +4 -1
  36. package/source/except.d.ts +3 -1
  37. package/source/exclude-rest-element.d.ts +40 -0
  38. package/source/exclude-strict.d.ts +2 -0
  39. package/source/exclusify-union.d.ts +113 -0
  40. package/source/extends-strict.d.ts +2 -0
  41. package/source/extract-rest-element.d.ts +30 -0
  42. package/source/extract-strict.d.ts +3 -1
  43. package/source/find-global-type.d.ts +2 -0
  44. package/source/fixed-length-array.d.ts +67 -21
  45. package/source/get.d.ts +5 -3
  46. package/source/global-this.d.ts +2 -0
  47. package/source/globals/index.d.ts +2 -0
  48. package/source/globals/observable-like.d.ts +5 -0
  49. package/source/greater-than-or-equal.d.ts +9 -1
  50. package/source/greater-than.d.ts +2 -0
  51. package/source/has-optional-keys.d.ts +2 -0
  52. package/source/has-readonly-keys.d.ts +2 -0
  53. package/source/has-required-keys.d.ts +2 -0
  54. package/source/has-writable-keys.d.ts +2 -0
  55. package/source/if-any.d.ts +2 -0
  56. package/source/if-empty-object.d.ts +2 -0
  57. package/source/if-never.d.ts +2 -0
  58. package/source/if-null.d.ts +2 -0
  59. package/source/if-unknown.d.ts +2 -0
  60. package/source/if.d.ts +37 -0
  61. package/source/includes.d.ts +2 -0
  62. package/source/int-closed-range.d.ts +3 -1
  63. package/source/int-range.d.ts +8 -6
  64. package/source/internal/array.d.ts +2 -9
  65. package/source/internal/characters.d.ts +2 -0
  66. package/source/{enforce-optional.d.ts → internal/enforce-optional.d.ts} +3 -1
  67. package/source/internal/index.d.ts +3 -0
  68. package/source/internal/keys.d.ts +2 -0
  69. package/source/internal/numeric.d.ts +2 -0
  70. package/source/internal/object.d.ts +2 -0
  71. package/source/internal/string.d.ts +4 -2
  72. package/source/internal/tuple.d.ts +2 -13
  73. package/source/internal/type.d.ts +34 -0
  74. package/source/invariant-of.d.ts +2 -0
  75. package/source/is-any.d.ts +2 -0
  76. package/source/is-equal.d.ts +15 -0
  77. package/source/is-float.d.ts +2 -0
  78. package/source/is-integer.d.ts +2 -0
  79. package/source/is-literal.d.ts +4 -2
  80. package/source/is-lowercase.d.ts +2 -0
  81. package/source/is-never.d.ts +2 -0
  82. package/source/is-null.d.ts +2 -0
  83. package/source/is-nullable.d.ts +2 -0
  84. package/source/is-optional-key-of.d.ts +2 -0
  85. package/source/is-optional.d.ts +2 -0
  86. package/source/is-readonly-key-of.d.ts +2 -0
  87. package/source/is-required-key-of.d.ts +2 -0
  88. package/source/is-tuple.d.ts +2 -0
  89. package/source/is-undefined.d.ts +2 -0
  90. package/source/is-union.d.ts +2 -0
  91. package/source/is-unknown.d.ts +2 -0
  92. package/source/is-uppercase.d.ts +2 -0
  93. package/source/is-writable-key-of.d.ts +2 -0
  94. package/source/iterable-element.d.ts +2 -0
  95. package/source/join.d.ts +2 -0
  96. package/source/json-value.d.ts +3 -1
  97. package/source/jsonifiable.d.ts +2 -0
  98. package/source/jsonify.d.ts +2 -0
  99. package/source/kebab-case.d.ts +4 -2
  100. package/source/kebab-cased-properties-deep.d.ts +6 -4
  101. package/source/kebab-cased-properties.d.ts +6 -4
  102. package/source/key-as-string.d.ts +2 -0
  103. package/source/keys-of-union.d.ts +2 -0
  104. package/source/last-array-element.d.ts +3 -1
  105. package/source/less-than-or-equal.d.ts +2 -0
  106. package/source/less-than.d.ts +2 -0
  107. package/source/literal-to-primitive-deep.d.ts +3 -1
  108. package/source/literal-to-primitive.d.ts +2 -0
  109. package/source/literal-union.d.ts +3 -1
  110. package/source/merge-deep.d.ts +3 -1
  111. package/source/merge-exclusive.d.ts +1 -0
  112. package/source/merge.d.ts +2 -0
  113. package/source/multidimensional-array.d.ts +2 -0
  114. package/source/multidimensional-readonly-array.d.ts +2 -0
  115. package/source/non-empty-object.d.ts +2 -0
  116. package/source/non-empty-string.d.ts +2 -0
  117. package/source/non-empty-tuple.d.ts +2 -0
  118. package/source/numeric.d.ts +23 -21
  119. package/source/omit-deep.d.ts +2 -0
  120. package/source/omit-index-signature.d.ts +3 -1
  121. package/source/opaque.d.ts +2 -0
  122. package/source/optional-keys-of.d.ts +2 -0
  123. package/source/or.d.ts +9 -5
  124. package/source/override-properties.d.ts +2 -0
  125. package/source/package-json.d.ts +38 -16
  126. package/source/partial-deep.d.ts +20 -17
  127. package/source/partial-on-undefined-deep.d.ts +3 -1
  128. package/source/pascal-case.d.ts +5 -3
  129. package/source/pascal-cased-properties-deep.d.ts +6 -4
  130. package/source/pascal-cased-properties.d.ts +6 -4
  131. package/source/paths.d.ts +2 -0
  132. package/source/pick-deep.d.ts +8 -5
  133. package/source/pick-index-signature.d.ts +3 -1
  134. package/source/primitive.d.ts +2 -0
  135. package/source/promisable.d.ts +2 -0
  136. package/source/readonly-deep.d.ts +6 -4
  137. package/source/readonly-keys-of.d.ts +2 -0
  138. package/source/readonly-tuple.d.ts +6 -15
  139. package/source/remove-prefix.d.ts +4 -2
  140. package/source/replace.d.ts +3 -1
  141. package/source/require-all-or-none.d.ts +2 -0
  142. package/source/require-at-least-one.d.ts +2 -0
  143. package/source/require-exactly-one.d.ts +2 -0
  144. package/source/require-one-or-none.d.ts +2 -0
  145. package/source/required-deep.d.ts +4 -1
  146. package/source/required-keys-of.d.ts +2 -0
  147. package/source/schema.d.ts +2 -0
  148. package/source/screaming-snake-case.d.ts +4 -2
  149. package/source/set-field-type.d.ts +3 -1
  150. package/source/set-non-nullable-deep.d.ts +2 -0
  151. package/source/set-non-nullable.d.ts +2 -0
  152. package/source/set-optional.d.ts +2 -0
  153. package/source/set-parameter-type.d.ts +2 -0
  154. package/source/set-readonly.d.ts +2 -0
  155. package/source/set-required-deep.d.ts +2 -0
  156. package/source/set-required.d.ts +2 -0
  157. package/source/set-return-type.d.ts +2 -0
  158. package/source/shared-union-fields-deep.d.ts +3 -1
  159. package/source/shared-union-fields.d.ts +4 -2
  160. package/source/simplify-deep.d.ts +3 -1
  161. package/source/simplify.d.ts +3 -1
  162. package/source/single-key-object.d.ts +2 -0
  163. package/source/snake-case.d.ts +4 -2
  164. package/source/snake-cased-properties-deep.d.ts +6 -4
  165. package/source/snake-cased-properties.d.ts +6 -4
  166. package/source/split-on-rest-element.d.ts +106 -0
  167. package/source/split.d.ts +3 -1
  168. package/source/spread.d.ts +2 -0
  169. package/source/string-repeat.d.ts +2 -0
  170. package/source/string-slice.d.ts +2 -0
  171. package/source/stringified.d.ts +2 -0
  172. package/source/structured-cloneable.d.ts +2 -0
  173. package/source/subtract.d.ts +6 -3
  174. package/source/sum.d.ts +5 -2
  175. package/source/tagged-union.d.ts +2 -0
  176. package/source/tagged.d.ts +3 -0
  177. package/source/trim.d.ts +2 -0
  178. package/source/tsconfig-json.d.ts +54 -25
  179. package/source/tuple-of.d.ts +78 -0
  180. package/source/tuple-to-object.d.ts +2 -0
  181. package/source/tuple-to-union.d.ts +2 -0
  182. package/source/typed-array.d.ts +2 -0
  183. package/source/undefined-on-partial-deep.d.ts +2 -0
  184. package/source/union-to-intersection.d.ts +3 -1
  185. package/source/union-to-tuple.d.ts +2 -0
  186. package/source/unknown-array.d.ts +2 -0
  187. package/source/unknown-map.d.ts +2 -0
  188. package/source/unknown-record.d.ts +2 -0
  189. package/source/unknown-set.d.ts +2 -0
  190. package/source/value-of.d.ts +2 -0
  191. package/source/words.d.ts +4 -2
  192. package/source/writable-deep.d.ts +6 -5
  193. package/source/writable-keys-of.d.ts +2 -0
  194. package/source/writable.d.ts +2 -0
  195. package/source/xor.d.ts +83 -0
package/index.d.ts CHANGED
@@ -111,6 +111,9 @@ export type {WritableKeysOf} from './source/writable-keys-of.d.ts';
111
111
  export type {IsWritableKeyOf} from './source/is-writable-key-of.d.ts';
112
112
  export type {HasWritableKeys} from './source/has-writable-keys.d.ts';
113
113
  export type {Spread} from './source/spread.d.ts';
114
+ export type {SplitOnRestElement} from './source/split-on-rest-element.d.ts';
115
+ export type {ExtractRestElement} from './source/extract-rest-element.d.ts';
116
+ export type {ExcludeRestElement} from './source/exclude-rest-element.d.ts';
114
117
  export type {IsInteger} from './source/is-integer.d.ts';
115
118
  export type {IsFloat} from './source/is-float.d.ts';
116
119
  export type {TupleToObject} from './source/tuple-to-object.d.ts';
@@ -138,6 +141,7 @@ export type {ArrayValues} from './source/array-values.d.ts';
138
141
  export type {ArraySlice} from './source/array-slice.d.ts';
139
142
  export type {ArraySplice} from './source/array-splice.d.ts';
140
143
  export type {ArrayTail} from './source/array-tail.d.ts';
144
+ export type {ArrayElement} from './source/array-element.d.ts';
141
145
  export type {SetFieldType, SetFieldTypeOptions} from './source/set-field-type.d.ts';
142
146
  export type {Paths, PathsOptions} from './source/paths.d.ts';
143
147
  export type {AllUnionFields} from './source/all-union-fields.d.ts';
@@ -148,6 +152,7 @@ export type {IfNull} from './source/if-null.d.ts';
148
152
  export type {IsUndefined} from './source/is-undefined.d.ts';
149
153
  export type {And} from './source/and.d.ts';
150
154
  export type {Or} from './source/or.d.ts';
155
+ export type {Xor} from './source/xor.d.ts';
151
156
  export type {AllExtend, AllExtendOptions} from './source/all-extend.d.ts';
152
157
  export type {NonEmptyTuple} from './source/non-empty-tuple.d.ts';
153
158
  export type {FindGlobalInstanceType, FindGlobalType} from './source/find-global-type.d.ts';
@@ -157,6 +162,8 @@ export type {IsLowercase} from './source/is-lowercase.d.ts';
157
162
  export type {IsUppercase} from './source/is-uppercase.d.ts';
158
163
  export type {IsOptional} from './source/is-optional.d.ts';
159
164
  export type {IsNullable} from './source/is-nullable.d.ts';
165
+ export type {TupleOf} from './source/tuple-of.d.ts';
166
+ export type {ExclusifyUnion} from './source/exclusify-union.d.ts';
160
167
 
161
168
  // Template literal types
162
169
  export type {CamelCase, CamelCaseOptions} from './source/camel-case.d.ts';
@@ -197,3 +204,5 @@ export type {TsConfigJson} from './source/tsconfig-json.d.ts';
197
204
  export type {ExtendsStrict} from './source/extends-strict.d.ts';
198
205
  export type {ExtractStrict} from './source/extract-strict.d.ts';
199
206
  export type {ExcludeStrict} from './source/exclude-strict.d.ts';
207
+
208
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "5.0.1",
3
+ "version": "5.2.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -28,6 +28,7 @@
28
28
  "test:tsc": "tsc",
29
29
  "test:tsd": "tsd",
30
30
  "test:xo": "xo",
31
+ "test:linter": "node --test",
31
32
  "test": "run-p test:*"
32
33
  },
33
34
  "files": [
@@ -53,6 +54,8 @@
53
54
  },
54
55
  "devDependencies": {
55
56
  "@sindresorhus/tsconfig": "^8.0.1",
57
+ "@typescript-eslint/parser": "^8.44.0",
58
+ "eslint": "^9.35.0",
56
59
  "expect-type": "^1.2.2",
57
60
  "npm-run-all2": "^8.0.4",
58
61
  "tsd": "^0.33.0",
package/readme.md CHANGED
@@ -60,6 +60,8 @@ npm install type-fest
60
60
  > [!NOTE]
61
61
  > This readme shows the current development version. For docs about the latest version, see the [npm page](https://www.npmjs.com/package/type-fest).
62
62
 
63
+ *You may also like my [`ts-extras`](https://github.com/sindresorhus/ts-extras) package which provides runtime functions for some of these types.*
64
+
63
65
  ## Usage
64
66
 
65
67
  ```ts
@@ -167,8 +169,8 @@ Click the type names for complete docs.
167
169
  - [`IntClosedRange`](source/int-closed-range.d.ts) - Generate a union of numbers (includes the start and the end).
168
170
  - [`ArrayIndices`](source/array-indices.d.ts) - Provides valid indices for a constant array or tuple.
169
171
  - [`ArrayValues`](source/array-values.d.ts) - Provides all values for a constant array or tuple.
170
- - [`ArraySplice`](source/array-splice.d.ts) - Creates a new array type by adding or removing elements at a specified index range in the original array.
171
- - [`ArrayTail`](source/array-tail.d.ts) - Extracts the type of an array or tuple minus the first element.
172
+ - [`ArraySplice`](source/array-splice.d.ts) - Create a new array type by adding or removing elements at a specified index range in the original array.
173
+ - [`ArrayTail`](source/array-tail.d.ts) - Extract the type of an array or tuple minus the first element.
172
174
  - [`SetFieldType`](source/set-field-type.d.ts) - Create a type that changes the type of the given keys.
173
175
  - [`Paths`](source/paths.d.ts) - Generate a union of all possible paths to properties in the given object.
174
176
  - [`SharedUnionFields`](source/shared-union-fields.d.ts) - Create a type with shared fields from a union of object types.
@@ -177,7 +179,8 @@ Click the type names for complete docs.
177
179
  - [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union.
178
180
  - [`DistributedPick`](source/distributed-pick.d.ts) - Picks keys from a type, distributing the operation over a union.
179
181
  - [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true.
180
- - [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types are true.
182
+ - [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types is true.
183
+ - [`Xor`](source/xor.d.ts) - Returns a boolean for whether only one of two given types is true.
181
184
  - [`AllExtend`](source/all-extend.d.ts) - Returns a boolean for whether every element in an array type extends another type.
182
185
  - [`NonEmptyTuple`](source/non-empty-tuple.d.ts) - Matches any non-empty tuple.
183
186
  - [`NonEmptyString`](source/non-empty-string.d.ts) - Matches any non-empty string.
@@ -185,6 +188,7 @@ Click the type names for complete docs.
185
188
  - [`FindGlobalInstanceType`](source/find-global-type.d.ts) - Tries to find one or more types from their globally-defined constructors.
186
189
  - [`ConditionalSimplify`](source/conditional-simplify.d.ts) - Simplifies a type while including and/or excluding certain types from being simplified.
187
190
  - [`ConditionalSimplifyDeep`](source/conditional-simplify-deep.d.ts) - Recursively simplifies a type while including and/or excluding certain types from being simplified.
191
+ - [`ExclusifyUnion`](source/exclusify-union.d.ts) - Ensure mutual exclusivity in object unions by adding other members’ keys as `?: never`.
188
192
 
189
193
  ### Type Guard
190
194
 
@@ -238,7 +242,7 @@ Click the type names for complete docs.
238
242
  - [`Replace`](source/replace.d.ts) - Represents a string with some or all matches replaced by a replacement.
239
243
  - [`StringSlice`](source/string-slice.d.ts) - Returns a string slice of a given range, just like `String#slice()`.
240
244
  - [`StringRepeat`](source/string-repeat.d.ts) - Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
241
- - [`RemovePrefix`](source/remove-prefix.d.ts) - Removes the specified prefix from the start of a string.
245
+ - [`RemovePrefix`](source/remove-prefix.d.ts) - Remove the specified prefix from the start of a string.
242
246
 
243
247
  ### Array
244
248
 
@@ -246,14 +250,19 @@ Click the type names for complete docs.
246
250
  - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
247
251
  - [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
248
252
  - [`ArraySlice`](source/array-slice.d.ts) - Returns an array slice of a given range, just like `Array#slice()`.
249
- - [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
250
- - [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
253
+ - [`ArrayElement`](source/array-element.d.ts) - Extracts the element type of an array or tuple.
254
+ - [`LastArrayElement`](source/last-array-element.d.ts) - Extract the type of the last element of an array.
255
+ - [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length. The `Array` prototype methods that manipulate its length are excluded from the resulting type.
251
256
  - [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
252
257
  - [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
253
258
  - [`ReadonlyTuple`](source/readonly-tuple.d.ts) - Create a type that represents a read-only tuple of the given type and length.
254
259
  - [`TupleToUnion`](source/tuple-to-union.d.ts) - Convert a tuple/array into a union type of its elements.
255
260
  - [`UnionToTuple`](source/union-to-tuple.d.ts) - Convert a union type into an unordered tuple type of its elements.
256
261
  - [`TupleToObject`](source/tuple-to-object.d.ts) - Transforms a tuple into an object, mapping each tuple index to its corresponding type as a key-value pair.
262
+ - [`TupleOf`](source/tuple-of.d.ts) - Create a tuple type of the specified length with elements of the specified type.
263
+ - [`SplitOnRestElement`](source/split-on-rest-element.d.ts) - Splits an array into three parts, where the first contains all elements before the rest element, the second is the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element itself, and the third contains all elements after the rest element.
264
+ - [`ExtractRestElement`](source/extract-rest-element.d.ts) - Extract the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element type from an array.
265
+ - [`ExcludeRestElement`](source/exclude-rest-element.d.ts) - Create a tuple with the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element removed.
257
266
 
258
267
  ### Numeric
259
268
 
@@ -283,11 +292,11 @@ Click the type names for complete docs.
283
292
  - [`CamelCasedProperties`](source/camel-cased-properties.d.ts) - Convert object properties to camel-case (`fooBar`).
284
293
  - [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) - Convert object properties to camel-case recursively (`fooBar`).
285
294
  - [`KebabCase`](source/kebab-case.d.ts) - Convert a string literal to kebab-case (`foo-bar`).
286
- - [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert a object properties to kebab-case recursively (`foo-bar`).
287
- - [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab-case (`foo-bar`).
288
- - [`PascalCase`](source/pascal-case.d.ts) - Converts a string literal to pascal-case (`FooBar`)
289
- - [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Converts object properties to pascal-case (`FooBar`)
290
- - [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Converts object properties to pascal-case (`FooBar`)
295
+ - [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) - Convert object properties to kebab-case (`foo-bar`).
296
+ - [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) - Convert object properties to kebab-case recursively (`foo-bar`).
297
+ - [`PascalCase`](source/pascal-case.d.ts) - Convert a string literal to pascal-case (`FooBar`).
298
+ - [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) - Convert object properties to pascal-case (`FooBar`).
299
+ - [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) - Convert object properties to pascal-case recursively (`FooBar`).
291
300
  - [`SnakeCase`](source/snake-case.d.ts) - Convert a string literal to snake-case (`foo_bar`).
292
301
  - [`SnakeCasedProperties`](source/snake-cased-properties.d.ts) - Convert object properties to snake-case (`foo_bar`).
293
302
  - [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) - Convert object properties to snake-case recursively (`foo_bar`).
@@ -342,6 +351,7 @@ Click the type names for complete docs.
342
351
  - `HomomorphicOmit` - See [`Except`](source/except.d.ts)
343
352
  - `IfAny`, `IfNever`, `If*` - See [`If`](source/if.d.ts)
344
353
  - `MaybePromise` - See [`Promisable`](source/promisable.d.ts)
354
+ - `ReadonlyTuple` - See [`TupleOf`](source/tuple-of.d.ts)
345
355
 
346
356
  ## Tips
347
357
 
@@ -10,7 +10,7 @@ import type {UnknownArray} from './unknown-array.d.ts';
10
10
  /**
11
11
  @see {@link AllExtend}
12
12
  */
13
- type AllExtendOptions = {
13
+ export type AllExtendOptions = {
14
14
  /**
15
15
  Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
16
16
 
@@ -113,3 +113,5 @@ type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllE
113
113
  : false
114
114
  : true
115
115
  >, false, false>;
116
+
117
+ export {};
@@ -62,7 +62,7 @@ function displayPetInfo(petInfo: AllUnionFields<Cat | Dog>) {
62
62
  }
63
63
  ```
64
64
 
65
- @see SharedUnionFields
65
+ @see {@link SharedUnionFields}
66
66
 
67
67
  @category Object
68
68
  @category Union
@@ -86,3 +86,5 @@ Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<un
86
86
  >
87
87
  : never
88
88
  : never;
89
+
90
+ export {};
package/source/and.d.ts CHANGED
@@ -46,6 +46,7 @@ type E = And<boolean, boolean>;
46
46
  ```
47
47
 
48
48
  Note: If either of the types is `never`, the result becomes `false`.
49
+
49
50
  @example
50
51
  ```
51
52
  import type {And} from 'type-fest';
@@ -73,5 +74,8 @@ type G = And<never, never>;
73
74
  ```
74
75
 
75
76
  @see {@link Or}
77
+ @see {@link Xor}
76
78
  */
77
79
  export type And<A extends boolean, B extends boolean> = AllExtend<[A, B], true>;
80
+
81
+ export {};
@@ -0,0 +1,46 @@
1
+ import type {UnknownArray} from './unknown-array.d.ts';
2
+
3
+ /**
4
+ Extracts the element type of an array or tuple.
5
+
6
+ Use-cases:
7
+ - When you need type-safe element extraction that returns `never` for non-arrays.
8
+ - When extracting element types from generic array parameters in function signatures.
9
+ - For better readability and explicit intent over using `T[number]` directly.
10
+
11
+ Note: Returns `never` if the type is not an array.
12
+
13
+ @example
14
+ ```
15
+ import type {ArrayElement} from 'type-fest';
16
+
17
+ // Arrays
18
+ type StringArray = ArrayElement<string[]>;
19
+ //=> string
20
+
21
+ // Tuples
22
+ type Tuple = ArrayElement<[1, 2, 3]>;
23
+ //=> 1 | 2 | 3
24
+
25
+ // Type-safe
26
+ type NotArray = ArrayElement<{a: string}>;
27
+ //=> never
28
+
29
+ // Practical example
30
+ declare function getRandomElement<T extends readonly unknown[]>(array: T): ArrayElement<T>;
31
+
32
+ getRandomElement(['foo', 'bar', 'baz'] as const);
33
+ //=> 'foo' | 'bar' | 'baz'
34
+ ```
35
+
36
+ @see {@link ArrayValues} - For directly extracting values from a constant array type.
37
+ @see {@link IterableElement} - For iterables like `Set`, `Map`, and generators (not suitable for all use cases due to different inference behavior).
38
+
39
+ @category Array
40
+ */
41
+ export type ArrayElement<T> =
42
+ T extends UnknownArray
43
+ ? T[number]
44
+ : never;
45
+
46
+ export {};
@@ -21,3 +21,5 @@ const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
21
21
  */
22
22
  export type ArrayIndices<Element extends readonly unknown[]> =
23
23
  Exclude<Partial<Element>['length'], Element['length']>;
24
+
25
+ export {};
@@ -107,3 +107,5 @@ type ArraySliceByPositiveIndex<
107
107
  > = Start extends End
108
108
  ? Result
109
109
  : ArraySliceByPositiveIndex<Array_, Sum<Start, 1>, End, [...Result, Array_[Start]]>;
110
+
111
+ export {};
@@ -1,7 +1,8 @@
1
- import type {BuildTuple, StaticPartOfArray, VariablePartOfArray} from './internal/index.d.ts';
1
+ import type {StaticPartOfArray, VariablePartOfArray} from './internal/index.d.ts';
2
2
  import type {GreaterThanOrEqual} from './greater-than-or-equal.d.ts';
3
3
  import type {Subtract} from './subtract.d.ts';
4
4
  import type {UnknownArray} from './unknown-array.d.ts';
5
+ import type {TupleOf} from './tuple-of.d.ts';
5
6
 
6
7
  /**
7
8
  The implementation of `SplitArrayByIndex` for fixed length arrays.
@@ -9,7 +10,7 @@ The implementation of `SplitArrayByIndex` for fixed length arrays.
9
10
  type SplitFixedArrayByIndex<T extends UnknownArray, SplitIndex extends number> =
10
11
  SplitIndex extends 0
11
12
  ? [[], T]
12
- : T extends readonly [...BuildTuple<SplitIndex>, ...infer V]
13
+ : T extends readonly [...TupleOf<SplitIndex>, ...infer V]
13
14
  ? T extends readonly [...infer U, ...V]
14
15
  ? [U, V]
15
16
  : [never, never]
@@ -22,7 +23,7 @@ type SplitVariableArrayByIndex<T extends UnknownArray,
22
23
  SplitIndex extends number,
23
24
  T1 = Subtract<SplitIndex, StaticPartOfArray<T>['length']>,
24
25
  T2 = T1 extends number
25
- ? BuildTuple<GreaterThanOrEqual<T1, 0> extends true ? T1 : number, VariablePartOfArray<T>[number]>
26
+ ? TupleOf<GreaterThanOrEqual<T1, 0> extends true ? T1 : number, VariablePartOfArray<T>[number]>
26
27
  : [],
27
28
  > =
28
29
  SplitIndex extends 0
@@ -63,7 +64,7 @@ type SplitArrayByIndex<T extends UnknownArray, SplitIndex extends number> =
63
64
  : SplitFixedArrayByIndex<T, SplitIndex>;
64
65
 
65
66
  /**
66
- Creates a new array type by adding or removing elements at a specified index range in the original array.
67
+ Create a new array type by adding or removing elements at a specified index range in the original array.
67
68
 
68
69
  Use-case: Replace or insert items in an array type.
69
70
 
@@ -97,3 +98,5 @@ export type ArraySplice<
97
98
  ? [...U, ...Items, ...X]
98
99
  : never // Should never happen
99
100
  : never; // Should never happen
101
+
102
+ export {};
@@ -3,7 +3,7 @@ import type {IfNotAnyOrNever, IsArrayReadonly} from './internal/index.d.ts';
3
3
  import type {UnknownArray} from './unknown-array.d.ts';
4
4
 
5
5
  /**
6
- Extracts the type of an array or tuple minus the first element.
6
+ Extract the type of an array or tuple minus the first element.
7
7
 
8
8
  @example
9
9
  ```
@@ -66,3 +66,5 @@ type _ArrayTail<TArray extends UnknownArray> = TArray extends readonly [unknown?
66
66
  : TArray // Happens when `TArray` is a non-tuple array (e.g., `string[]`) or has a leading rest element (e.g., `[...string[], number]`)
67
67
  : Tail
68
68
  : [];
69
+
70
+ export {};
@@ -20,3 +20,5 @@ const getWeekdayName = (day: Weekday): WeekdayName => weekdays[day];
20
20
  @category Array
21
21
  */
22
22
  export type ArrayValues<T extends readonly unknown[]> = T[number];
23
+
24
+ export {};
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  Create a type that represents either the value or an array of the value.
3
3
 
4
- @see Promisable
4
+ @see {@link Promisable}
5
5
 
6
6
  @example
7
7
  ```
@@ -27,3 +27,5 @@ export type Arrayable<T> =
27
27
  T
28
28
  // TODO: Use `readonly T[]` when this issue is resolved: https://github.com/microsoft/TypeScript/issues/17002
29
29
  | T[];
30
+
31
+ export {};
@@ -21,3 +21,5 @@ asyncFunction().then(value => doSomething(value));
21
21
  @category Async
22
22
  */
23
23
  export type AsyncReturnType<Target extends AsyncFunction> = Awaited<ReturnType<Target>>;
24
+
25
+ export {};
@@ -30,3 +30,5 @@ const getFooAsync: AsyncifiedFooGetter = (someArg) => {
30
30
  @category Async
31
31
  */
32
32
  export type Asyncify<Function_ extends (...arguments_: any[]) => any> = SetReturnType<Function_, Promise<Awaited<ReturnType<Function_>>>>;
33
+
34
+ export {};
package/source/basic.d.ts CHANGED
@@ -34,3 +34,5 @@ Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/relea
34
34
  @category Class
35
35
  */
36
36
  export type AbstractConstructor<T, Arguments extends unknown[] = any[]> = abstract new(...arguments_: Arguments) => T;
37
+
38
+ export {};
@@ -1,12 +1,12 @@
1
1
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
2
- import type {Words} from './words.d.ts';
2
+ import type {Words, WordsOptions} from './words.d.ts';
3
3
 
4
4
  /**
5
5
  CamelCase options.
6
6
 
7
7
  @see {@link CamelCase}
8
8
  */
9
- export type CamelCaseOptions = {
9
+ export type CamelCaseOptions = WordsOptions & {
10
10
  /**
11
11
  Whether to preserved consecutive uppercase letter.
12
12
 
@@ -15,7 +15,8 @@ export type CamelCaseOptions = {
15
15
  preserveConsecutiveUppercase?: boolean;
16
16
  };
17
17
 
18
- export type DefaultCamelCaseOptions = {
18
+ export type _DefaultCamelCaseOptions = {
19
+ splitOnNumbers: true;
19
20
  preserveConsecutiveUppercase: false;
20
21
  };
21
22
 
@@ -83,7 +84,9 @@ export type CamelCase<Type, Options extends CamelCaseOptions = {}> = Type extend
83
84
  ? string extends Type
84
85
  ? Type
85
86
  : Uncapitalize<CamelCaseFromArray<
86
- Words<Type extends Uppercase<Type> ? Lowercase<Type> : Type>,
87
- ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>
87
+ Words<Type extends Uppercase<Type> ? Lowercase<Type> : Type, Options>,
88
+ ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>
88
89
  >>
89
90
  : Type;
91
+
92
+ export {};
@@ -1,4 +1,4 @@
1
- import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case.d.ts';
1
+ import type {CamelCase, CamelCaseOptions, _DefaultCamelCaseOptions} from './camel-case.d.ts';
2
2
  import type {ApplyDefaultOptions, NonRecursiveType} from './internal/index.d.ts';
3
3
  import type {UnknownArray} from './unknown-array.d.ts';
4
4
 
@@ -7,8 +7,8 @@ Convert object properties to camel case recursively.
7
7
 
8
8
  This can be useful when, for example, converting some API types from a different style.
9
9
 
10
- @see CamelCasedProperties
11
- @see CamelCase
10
+ @see {@link CamelCasedProperties}
11
+ @see {@link CamelCase}
12
12
 
13
13
  @example
14
14
  ```
@@ -57,7 +57,7 @@ const preserveConsecutiveUppercase: CamelCasedPropertiesDeep<{fooBAR: {fooBARBiz
57
57
  export type CamelCasedPropertiesDeep<
58
58
  Value,
59
59
  Options extends CamelCaseOptions = {},
60
- > = _CamelCasedPropertiesDeep<Value, ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>>;
60
+ > = _CamelCasedPropertiesDeep<Value, ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>>;
61
61
 
62
62
  type _CamelCasedPropertiesDeep<
63
63
  Value,
@@ -95,3 +95,5 @@ type CamelCasedPropertiesArrayDeep<
95
95
  : Value extends ReadonlyArray<infer U>
96
96
  ? ReadonlyArray<_CamelCasedPropertiesDeep<U, Options>>
97
97
  : never;
98
+
99
+ export {};
@@ -1,4 +1,4 @@
1
- import type {CamelCase, CamelCaseOptions, DefaultCamelCaseOptions} from './camel-case.d.ts';
1
+ import type {CamelCase, CamelCaseOptions, _DefaultCamelCaseOptions} from './camel-case.d.ts';
2
2
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
 
4
4
  /**
@@ -6,8 +6,8 @@ Convert object properties to camel case but not recursively.
6
6
 
7
7
  This can be useful when, for example, converting some API types from a different style.
8
8
 
9
- @see CamelCasedPropertiesDeep
10
- @see CamelCase
9
+ @see {@link CamelCasedPropertiesDeep}
10
+ @see {@link CamelCase}
11
11
 
12
12
  @example
13
13
  ```
@@ -38,6 +38,8 @@ export type CamelCasedProperties<Value, Options extends CamelCaseOptions = {}> =
38
38
  ? Value
39
39
  : {
40
40
  [K in keyof Value as
41
- CamelCase<K, ApplyDefaultOptions<CamelCaseOptions, DefaultCamelCaseOptions, Options>>
41
+ CamelCase<K, ApplyDefaultOptions<CamelCaseOptions, _DefaultCamelCaseOptions, Options>>
42
42
  ]: Value[K];
43
43
  };
44
+
45
+ export {};
@@ -58,3 +58,5 @@ const b: Alphanumeric = '#'; // Invalid
58
58
  @category Type
59
59
  */
60
60
  export type Alphanumeric = LowercaseLetter | UppercaseLetter | DigitCharacter;
61
+
62
+ export {};
@@ -43,3 +43,5 @@ export type ConditionalExcept<Base, Condition> = Except<
43
43
  Base,
44
44
  ConditionalKeys<Base, Condition>
45
45
  >;
46
+
47
+ export {};
@@ -59,3 +59,5 @@ type _ConditionalKeys<Base, Condition> = keyof {
59
59
  ExtendsStrict<Base[Key], Condition> extends true ? Key : never
60
60
  ]: never
61
61
  };
62
+
63
+ export {};
@@ -22,7 +22,7 @@ type AssertCondition<Type, Condition, Options extends ConditionalPickDeepOptions
22
22
  /**
23
23
  ConditionalPickDeep options.
24
24
 
25
- @see ConditionalPickDeep
25
+ @see {@link ConditionalPickDeep}
26
26
  */
27
27
  export type ConditionalPickDeepOptions = {
28
28
  /**
@@ -40,7 +40,7 @@ type DefaultConditionalPickDeepOptions = {
40
40
  /**
41
41
  Pick keys recursively from the shape that matches the given condition.
42
42
 
43
- @see ConditionalPick
43
+ @see {@link ConditionalPick}
44
44
 
45
45
  @example
46
46
  ```
@@ -116,3 +116,5 @@ type _ConditionalPickDeep<
116
116
  ? _ConditionalPickDeep<Type[Key], Condition, Options>
117
117
  : typeof conditionalPickDeepSymbol;
118
118
  }, (typeof conditionalPickDeepSymbol | undefined) | EmptyObject>, never, UnknownRecord>;
119
+
120
+ export {};
@@ -42,3 +42,5 @@ export type ConditionalPick<Base, Condition> = Pick<
42
42
  Base,
43
43
  ConditionalKeys<Base, Condition>
44
44
  >;
45
+
46
+ export {};
@@ -61,7 +61,7 @@ type SimplifyDeepTypeAB = ConditionalSimplifyDeep<TypeA & TypeB, SomeComplexType
61
61
  // }
62
62
  ```
63
63
 
64
- @see SimplifyDeep
64
+ @see {@link SimplifyDeep}
65
65
  @category Object
66
66
  */
67
67
  export type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
@@ -69,3 +69,5 @@ export type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unk
69
69
  : Type extends IncludeType
70
70
  ? {[TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>}
71
71
  : Type;
72
+
73
+ export {};
@@ -38,7 +38,7 @@ type C = Simplify<{a: number} & {b: string}>;
38
38
  //=> {a: number; b: string}
39
39
  ```
40
40
 
41
- @see ConditionalSimplifyDeep
41
+ @see {@link ConditionalSimplifyDeep}
42
42
  @category Object
43
43
  */
44
44
  export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
@@ -46,3 +46,5 @@ export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown
46
46
  : Type extends IncludeType
47
47
  ? {[TypeKey in keyof Type]: Type[TypeKey]}
48
48
  : Type;
49
+
50
+ export {};
@@ -2,9 +2,9 @@ import type {ApplyDefaultOptions, AsciiPunctuation, StartsWith} from './internal
2
2
  import type {IsStringLiteral} from './is-literal.d.ts';
3
3
  import type {Merge} from './merge.d.ts';
4
4
  import type {RemovePrefix} from './remove-prefix.d.ts';
5
- import type {DefaultWordsOptions, Words, WordsOptions} from './words.d.ts';
5
+ import type {_DefaultWordsOptions, Words, WordsOptions} from './words.d.ts';
6
6
 
7
- export type DefaultDelimiterCaseOptions = Merge<DefaultWordsOptions, {splitOnNumbers: false}>;
7
+ export type _DefaultDelimiterCaseOptions = Merge<_DefaultWordsOptions, {splitOnNumbers: false}>;
8
8
 
9
9
  /**
10
10
  Convert an array of words to delimiter case starting with a delimiter with input capitalization.
@@ -27,8 +27,8 @@ Convert a string literal to a custom string delimiter casing.
27
27
 
28
28
  This can be useful when, for example, converting a camel-cased object property to an oddly cased one.
29
29
 
30
- @see KebabCase
31
- @see SnakeCase
30
+ @see {@link KebabCase}
31
+ @see {@link SnakeCase}
32
32
 
33
33
  @example
34
34
  ```
@@ -69,7 +69,9 @@ export type DelimiterCase<
69
69
  ? IsStringLiteral<Value> extends false
70
70
  ? Value
71
71
  : Lowercase<RemovePrefix<DelimiterCaseFromArray<
72
- Words<Value, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>,
72
+ Words<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>,
73
73
  Delimiter
74
74
  >, string, {strict: false}>>
75
75
  : Value;
76
+
77
+ export {};
@@ -1,4 +1,4 @@
1
- import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
1
+ import type {_DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
2
2
  import type {ApplyDefaultOptions, NonRecursiveType} from './internal/index.d.ts';
3
3
  import type {UnknownArray} from './unknown-array.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
@@ -8,8 +8,8 @@ Convert object properties to delimiter case recursively.
8
8
 
9
9
  This can be useful when, for example, converting some API types from a different style.
10
10
 
11
- @see DelimiterCase
12
- @see DelimiterCasedProperties
11
+ @see {@link DelimiterCase}
12
+ @see {@link DelimiterCasedProperties}
13
13
 
14
14
  @example
15
15
  ```
@@ -61,7 +61,7 @@ export type DelimiterCasedPropertiesDeep<
61
61
  Value,
62
62
  Delimiter extends string,
63
63
  Options extends WordsOptions = {},
64
- > = _DelimiterCasedPropertiesDeep<Value, Delimiter, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
64
+ > = _DelimiterCasedPropertiesDeep<Value, Delimiter, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
65
65
 
66
66
  type _DelimiterCasedPropertiesDeep<
67
67
  Value,
@@ -104,3 +104,5 @@ type DelimiterCasedPropertiesArrayDeep<
104
104
  : Value extends ReadonlyArray<infer U>
105
105
  ? ReadonlyArray<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>>
106
106
  : never;
107
+
108
+ export {};
@@ -1,4 +1,4 @@
1
- import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
1
+ import type {_DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
2
2
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
  import type {WordsOptions} from './words.d.ts';
4
4
 
@@ -7,8 +7,8 @@ Convert object properties to delimiter case but not recursively.
7
7
 
8
8
  This can be useful when, for example, converting some API types from a different style.
9
9
 
10
- @see DelimiterCase
11
- @see DelimiterCasedPropertiesDeep
10
+ @see {@link DelimiterCase}
11
+ @see {@link DelimiterCasedPropertiesDeep}
12
12
 
13
13
  @example
14
14
  ```
@@ -42,5 +42,7 @@ export type DelimiterCasedProperties<
42
42
  : Value extends Array<infer U>
43
43
  ? Value
44
44
  : {[K in keyof Value as
45
- DelimiterCase<K, Delimiter, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>
45
+ DelimiterCase<K, Delimiter, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>
46
46
  ]: Value[K]};
47
+
48
+ export {};