type-fest 5.0.0 → 5.1.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 (193) hide show
  1. package/index.d.ts +17 -12
  2. package/package.json +2 -1
  3. package/readme.md +18 -10
  4. package/source/all-extend.d.ts +3 -1
  5. package/source/all-union-fields.d.ts +2 -0
  6. package/source/and.d.ts +2 -0
  7. package/source/array-indices.d.ts +2 -0
  8. package/source/array-slice.d.ts +2 -0
  9. package/source/array-splice.d.ts +7 -4
  10. package/source/array-tail.d.ts +3 -1
  11. package/source/array-values.d.ts +2 -0
  12. package/source/arrayable.d.ts +2 -0
  13. package/source/async-return-type.d.ts +2 -0
  14. package/source/asyncify.d.ts +2 -0
  15. package/source/basic.d.ts +2 -0
  16. package/source/camel-case.d.ts +4 -2
  17. package/source/camel-cased-properties-deep.d.ts +4 -2
  18. package/source/camel-cased-properties.d.ts +4 -2
  19. package/source/characters.d.ts +2 -0
  20. package/source/conditional-except.d.ts +2 -0
  21. package/source/conditional-keys.d.ts +2 -0
  22. package/source/conditional-pick-deep.d.ts +2 -0
  23. package/source/conditional-pick.d.ts +2 -0
  24. package/source/conditional-simplify-deep.d.ts +2 -0
  25. package/source/conditional-simplify.d.ts +2 -0
  26. package/source/delimiter-case.d.ts +5 -3
  27. package/source/delimiter-cased-properties-deep.d.ts +4 -2
  28. package/source/delimiter-cased-properties.d.ts +4 -2
  29. package/source/distributed-omit.d.ts +2 -0
  30. package/source/distributed-pick.d.ts +2 -0
  31. package/source/empty-object.d.ts +2 -0
  32. package/source/entries.d.ts +7 -5
  33. package/source/entry.d.ts +10 -8
  34. package/source/exact.d.ts +2 -0
  35. package/source/except.d.ts +3 -1
  36. package/source/exclude-rest-element.d.ts +37 -0
  37. package/source/exclude-strict.d.ts +2 -0
  38. package/source/extends-strict.d.ts +2 -0
  39. package/source/extract-rest-element.d.ts +29 -0
  40. package/source/extract-strict.d.ts +2 -0
  41. package/source/find-global-type.d.ts +2 -0
  42. package/source/fixed-length-array.d.ts +67 -21
  43. package/source/get.d.ts +5 -3
  44. package/source/global-this.d.ts +2 -0
  45. package/source/globals/index.d.ts +2 -0
  46. package/source/globals/observable-like.d.ts +5 -0
  47. package/source/greater-than-or-equal.d.ts +2 -0
  48. package/source/greater-than.d.ts +2 -0
  49. package/source/has-optional-keys.d.ts +2 -0
  50. package/source/has-readonly-keys.d.ts +2 -0
  51. package/source/has-required-keys.d.ts +2 -0
  52. package/source/has-writable-keys.d.ts +2 -0
  53. package/source/if-any.d.ts +2 -0
  54. package/source/if-empty-object.d.ts +2 -0
  55. package/source/if-never.d.ts +2 -0
  56. package/source/if-null.d.ts +2 -0
  57. package/source/if-unknown.d.ts +2 -0
  58. package/source/if.d.ts +2 -0
  59. package/source/includes.d.ts +2 -0
  60. package/source/int-closed-range.d.ts +2 -0
  61. package/source/int-range.d.ts +7 -5
  62. package/source/internal/array.d.ts +2 -0
  63. package/source/internal/characters.d.ts +2 -0
  64. package/source/{enforce-optional.d.ts → internal/enforce-optional.d.ts} +3 -1
  65. package/source/internal/index.d.ts +3 -0
  66. package/source/internal/keys.d.ts +2 -0
  67. package/source/internal/numeric.d.ts +2 -0
  68. package/source/internal/object.d.ts +2 -0
  69. package/source/internal/string.d.ts +4 -2
  70. package/source/internal/tuple.d.ts +2 -13
  71. package/source/internal/type.d.ts +2 -0
  72. package/source/invariant-of.d.ts +2 -0
  73. package/source/is-any.d.ts +2 -0
  74. package/source/is-equal.d.ts +15 -0
  75. package/source/is-float.d.ts +2 -0
  76. package/source/is-integer.d.ts +2 -0
  77. package/source/is-literal.d.ts +4 -2
  78. package/source/is-lowercase.d.ts +2 -0
  79. package/source/is-never.d.ts +2 -0
  80. package/source/is-null.d.ts +2 -0
  81. package/source/is-nullable.d.ts +2 -0
  82. package/source/is-optional-key-of.d.ts +2 -0
  83. package/source/is-optional.d.ts +2 -0
  84. package/source/is-readonly-key-of.d.ts +2 -0
  85. package/source/is-required-key-of.d.ts +2 -0
  86. package/source/is-tuple.d.ts +2 -0
  87. package/source/is-undefined.d.ts +2 -0
  88. package/source/is-union.d.ts +2 -0
  89. package/source/is-unknown.d.ts +2 -0
  90. package/source/is-uppercase.d.ts +2 -0
  91. package/source/is-writable-key-of.d.ts +2 -0
  92. package/source/iterable-element.d.ts +2 -0
  93. package/source/join.d.ts +2 -0
  94. package/source/json-value.d.ts +3 -1
  95. package/source/jsonifiable.d.ts +2 -0
  96. package/source/jsonify.d.ts +2 -0
  97. package/source/kebab-case.d.ts +4 -2
  98. package/source/kebab-cased-properties-deep.d.ts +4 -2
  99. package/source/kebab-cased-properties.d.ts +4 -2
  100. package/source/key-as-string.d.ts +2 -0
  101. package/source/keys-of-union.d.ts +2 -0
  102. package/source/last-array-element.d.ts +3 -1
  103. package/source/less-than-or-equal.d.ts +2 -0
  104. package/source/less-than.d.ts +2 -0
  105. package/source/literal-to-primitive-deep.d.ts +2 -0
  106. package/source/literal-to-primitive.d.ts +2 -0
  107. package/source/literal-union.d.ts +3 -1
  108. package/source/merge-deep.d.ts +3 -1
  109. package/source/merge-exclusive.d.ts +1 -0
  110. package/source/merge.d.ts +2 -0
  111. package/source/multidimensional-array.d.ts +2 -0
  112. package/source/multidimensional-readonly-array.d.ts +2 -0
  113. package/source/non-empty-object.d.ts +2 -0
  114. package/source/non-empty-string.d.ts +2 -0
  115. package/source/non-empty-tuple.d.ts +2 -0
  116. package/source/numeric.d.ts +7 -5
  117. package/source/omit-deep.d.ts +2 -0
  118. package/source/omit-index-signature.d.ts +2 -0
  119. package/source/opaque.d.ts +2 -0
  120. package/source/optional-keys-of.d.ts +2 -0
  121. package/source/or.d.ts +2 -0
  122. package/source/override-properties.d.ts +2 -0
  123. package/source/package-json.d.ts +18 -16
  124. package/source/partial-deep.d.ts +20 -17
  125. package/source/partial-on-undefined-deep.d.ts +2 -0
  126. package/source/pascal-case.d.ts +5 -3
  127. package/source/pascal-cased-properties-deep.d.ts +4 -2
  128. package/source/pascal-cased-properties.d.ts +4 -2
  129. package/source/paths.d.ts +2 -0
  130. package/source/pick-deep.d.ts +8 -5
  131. package/source/pick-index-signature.d.ts +2 -0
  132. package/source/primitive.d.ts +2 -0
  133. package/source/promisable.d.ts +2 -0
  134. package/source/readonly-deep.d.ts +6 -4
  135. package/source/readonly-keys-of.d.ts +2 -0
  136. package/source/readonly-tuple.d.ts +6 -15
  137. package/source/remove-prefix.d.ts +4 -2
  138. package/source/replace.d.ts +3 -1
  139. package/source/require-all-or-none.d.ts +2 -0
  140. package/source/require-at-least-one.d.ts +2 -0
  141. package/source/require-exactly-one.d.ts +2 -0
  142. package/source/require-one-or-none.d.ts +2 -0
  143. package/source/required-deep.d.ts +4 -1
  144. package/source/required-keys-of.d.ts +2 -0
  145. package/source/schema.d.ts +2 -0
  146. package/source/screaming-snake-case.d.ts +4 -2
  147. package/source/set-field-type.d.ts +3 -1
  148. package/source/set-non-nullable-deep.d.ts +2 -0
  149. package/source/set-non-nullable.d.ts +2 -0
  150. package/source/set-optional.d.ts +2 -0
  151. package/source/set-parameter-type.d.ts +2 -0
  152. package/source/set-readonly.d.ts +2 -0
  153. package/source/set-required-deep.d.ts +2 -0
  154. package/source/set-required.d.ts +2 -0
  155. package/source/set-return-type.d.ts +2 -0
  156. package/source/shared-union-fields-deep.d.ts +2 -0
  157. package/source/shared-union-fields.d.ts +2 -0
  158. package/source/simplify-deep.d.ts +2 -0
  159. package/source/simplify.d.ts +2 -0
  160. package/source/single-key-object.d.ts +2 -0
  161. package/source/snake-case.d.ts +4 -2
  162. package/source/snake-cased-properties-deep.d.ts +4 -2
  163. package/source/snake-cased-properties.d.ts +4 -2
  164. package/source/split-on-rest-element.d.ts +106 -0
  165. package/source/split.d.ts +3 -1
  166. package/source/spread.d.ts +2 -0
  167. package/source/string-repeat.d.ts +2 -0
  168. package/source/string-slice.d.ts +2 -0
  169. package/source/stringified.d.ts +2 -0
  170. package/source/structured-cloneable.d.ts +2 -0
  171. package/source/subtract.d.ts +6 -3
  172. package/source/sum.d.ts +5 -2
  173. package/source/tagged-union.d.ts +2 -0
  174. package/source/tagged.d.ts +3 -0
  175. package/source/trim.d.ts +2 -0
  176. package/source/tsconfig-json.d.ts +54 -25
  177. package/source/tuple-of.d.ts +78 -0
  178. package/source/tuple-to-object.d.ts +2 -0
  179. package/source/tuple-to-union.d.ts +2 -0
  180. package/source/typed-array.d.ts +2 -0
  181. package/source/undefined-on-partial-deep.d.ts +2 -0
  182. package/source/union-to-intersection.d.ts +3 -1
  183. package/source/union-to-tuple.d.ts +2 -0
  184. package/source/unknown-array.d.ts +2 -0
  185. package/source/unknown-map.d.ts +2 -0
  186. package/source/unknown-record.d.ts +2 -0
  187. package/source/unknown-set.d.ts +2 -0
  188. package/source/value-of.d.ts +2 -0
  189. package/source/words.d.ts +4 -2
  190. package/source/writable-deep.d.ts +5 -4
  191. package/source/writable-keys-of.d.ts +2 -0
  192. package/source/writable.d.ts +2 -0
  193. package/source/xor.d.ts +83 -0
@@ -41,11 +41,11 @@ export type ReadonlyDeep<T> = T extends BuiltIns
41
41
  : T extends new (...arguments_: any[]) => unknown
42
42
  ? T // Skip class constructors
43
43
  : T extends (...arguments_: any[]) => unknown
44
- ? {} extends ReadonlyObjectDeep<T>
44
+ ? {} extends _ReadonlyObjectDeep<T>
45
45
  ? T
46
46
  : HasMultipleCallSignatures<T> extends true
47
47
  ? T
48
- : ((...arguments_: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T>
48
+ : ((...arguments_: Parameters<T>) => ReturnType<T>) & _ReadonlyObjectDeep<T>
49
49
  : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>>
50
50
  ? ReadonlyMapDeep<KeyType, ValueType>
51
51
  : T extends Readonly<ReadonlySet<infer ItemType>>
@@ -60,7 +60,7 @@ export type ReadonlyDeep<T> = T extends BuiltIns
60
60
  : T extends ReadonlyArray<infer ItemType>
61
61
  ? ReadonlyArray<ReadonlyDeep<ItemType>>
62
62
  : T extends object
63
- ? ReadonlyObjectDeep<T>
63
+ ? _ReadonlyObjectDeep<T>
64
64
  : unknown;
65
65
 
66
66
  /**
@@ -76,6 +76,8 @@ type ReadonlySetDeep<ItemType> = {} & Readonly<ReadonlySet<ReadonlyDeep<ItemType
76
76
  /**
77
77
  Same as `ReadonlyDeep`, but accepts only `object`s as inputs. Internal helper for `ReadonlyDeep`.
78
78
  */
79
- type ReadonlyObjectDeep<ObjectType extends object> = {
79
+ export type _ReadonlyObjectDeep<ObjectType extends object> = {
80
80
  readonly [KeyType in keyof ObjectType]: ReadonlyDeep<ObjectType[KeyType]>
81
81
  };
82
+
83
+ export {};
@@ -34,3 +34,5 @@ export type ReadonlyKeysOf<Type extends object> =
34
34
  ]: never
35
35
  }) & keyof Type // Intersect with `keyof Type` to ensure result of `ReadonlyKeysOf<Type>` is always assignable to `keyof Type`
36
36
  : never; // Should never happen
37
+
38
+ export {};
@@ -1,13 +1,4 @@
1
- /**
2
- Creates a read-only tuple of type `Element` and with the length of `Length`.
3
-
4
- @private
5
- @see `ReadonlyTuple` which is safer because it tests if `Length` is a specific finite number.
6
- */
7
- type BuildTupleHelper<Element, Length extends number, Rest extends Element[]> =
8
- Rest['length'] extends Length ?
9
- readonly [...Rest] : // Terminate with readonly array (aka tuple)
10
- BuildTupleHelper<Element, Length, [Element, ...Rest]>;
1
+ import type {TupleOf} from './tuple-of.d.ts';
11
2
 
12
3
  /**
13
4
  Create a type that represents a read-only tuple of the given type and length.
@@ -32,10 +23,10 @@ guestFencingTeam.push('Sam');
32
23
  //=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
33
24
  ```
34
25
 
26
+ @deprecated This type will be removed in the next major version. Use the built-in `Readonly` type in combination with the {@link TupleOf} type instead, like `Readonly<TupleOf<Length, Element>>`.
27
+
35
28
  @category Utilities
36
29
  */
37
- export type ReadonlyTuple<Element, Length extends number> =
38
- number extends Length
39
- // Because `Length extends number` and `number extends Length`, then `Length` is not a specific finite number.
40
- ? readonly Element[] // It's not fixed length.
41
- : BuildTupleHelper<Element, Length, []>; // Otherwise it is a fixed length tuple.
30
+ export type ReadonlyTuple<Element, Length extends number> = Readonly<TupleOf<Length, Element>>;
31
+
32
+ export {};
@@ -6,7 +6,7 @@ import type {Or} from './or.d.ts';
6
6
  /**
7
7
  @see {@link RemovePrefix}
8
8
  */
9
- type RemovePrefixOptions = {
9
+ export type RemovePrefixOptions = {
10
10
  /**
11
11
  When enabled, instantiations with non-literal prefixes (e.g., `string`, `Uppercase<string>`, `` `on${string}` ``) simply return `string`, since their precise structure cannot be statically determined.
12
12
 
@@ -83,7 +83,7 @@ type DefaultRemovePrefixOptions = {
83
83
  };
84
84
 
85
85
  /**
86
- Removes the specified prefix from the start of a string.
86
+ Remove the specified prefix from the start of a string.
87
87
 
88
88
  @example
89
89
  ```
@@ -126,3 +126,5 @@ Prefix extends string // For distributing `Prefix`
126
126
  : string // Fallback to `string` when `Prefix` is non-literal and `strict` is disabled
127
127
  : S // Return back `S` when `Prefix` is not present at the start of `S`
128
128
  : never;
129
+
130
+ export {};
@@ -1,6 +1,6 @@
1
1
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
2
2
 
3
- type ReplaceOptions = {
3
+ export type ReplaceOptions = {
4
4
  all?: boolean;
5
5
  };
6
6
 
@@ -83,3 +83,5 @@ type _Replace<
83
83
  : `${Accumulator}${Input}`
84
84
  : never
85
85
  : never;
86
+
87
+ export {};
@@ -50,3 +50,5 @@ type _RequireAllOrNone<ObjectType, KeysType extends keyof ObjectType> = (
50
50
  | RequireAll<ObjectType, KeysType>
51
51
  | RequireNone<KeysType>
52
52
  ) & Omit<ObjectType, KeysType>; // The rest of the keys.
53
+
54
+ export {};
@@ -46,3 +46,5 @@ type _RequireAtLeastOne<
46
46
  }[KeysType] &
47
47
  // 3. Add the remaining keys not in `KeysType`
48
48
  Except<ObjectType, KeysType>;
49
+
50
+ export {};
@@ -44,3 +44,5 @@ type _RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType> =
44
44
  Required<Pick<ObjectType, Key>> &
45
45
  Partial<Record<Exclude<KeysType, Key>, never>>
46
46
  )}[KeysType] & Omit<ObjectType, KeysType>;
47
+
48
+ export {};
@@ -45,3 +45,5 @@ type _RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType> = (
45
45
  | RequireExactlyOne<ObjectType, KeysType>
46
46
  | RequireNone<KeysType>
47
47
  ) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
48
+
49
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type {BuiltIns, HasMultipleCallSignatures} from './internal/index.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
2
3
 
3
4
  /**
4
5
  Create a type from another type with all keys and nested keys set to required.
@@ -58,7 +59,7 @@ export type RequiredDeep<T> = T extends BuiltIns
58
59
  : T extends Promise<infer ValueType>
59
60
  ? Promise<RequiredDeep<ValueType>>
60
61
  : T extends (...arguments_: any[]) => unknown
61
- ? {} extends RequiredObjectDeep<T>
62
+ ? IsNever<keyof T> extends true
62
63
  ? T
63
64
  : HasMultipleCallSignatures<T> extends true
64
65
  ? T
@@ -70,3 +71,5 @@ export type RequiredDeep<T> = T extends BuiltIns
70
71
  type RequiredObjectDeep<ObjectType extends object> = {
71
72
  [KeyType in keyof ObjectType]-?: RequiredDeep<ObjectType[KeyType]>
72
73
  };
74
+
75
+ export {};
@@ -28,3 +28,5 @@ export type RequiredKeysOf<Type extends object> =
28
28
  Type extends unknown // For distributing `Type`
29
29
  ? Exclude<keyof Type, OptionalKeysOf<Type>>
30
30
  : never; // Should never happen
31
+
32
+ export {};
@@ -112,3 +112,5 @@ type SchemaHelper<Type, Value, Options extends Required<SchemaOptions>> = Simpli
112
112
  Value,
113
113
  Options>
114
114
  }>;
115
+
116
+ export {};
@@ -1,4 +1,4 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
1
+ import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
2
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
  import type {SnakeCase} from './snake-case.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
@@ -24,5 +24,7 @@ export type ScreamingSnakeCase<
24
24
  Value,
25
25
  Options extends WordsOptions = {},
26
26
  > = Value extends string
27
- ? Uppercase<SnakeCase<Value, ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>>
27
+ ? Uppercase<SnakeCase<Value, ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>>
28
28
  : Value;
29
+
30
+ export {};
@@ -1,7 +1,7 @@
1
1
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
2
2
  import type {Simplify} from './simplify.d.ts';
3
3
 
4
- type SetFieldTypeOptions = {
4
+ export type SetFieldTypeOptions = {
5
5
  /**
6
6
  Preserve optional and readonly modifiers for properties being updated.
7
7
 
@@ -63,3 +63,5 @@ type _SetFieldType<BaseType, Keys extends keyof BaseType, NewType, Options exten
63
63
  // `Record` is used to remove property modifiers
64
64
  Options['preservePropertyModifiers'] extends false ? Record<Keys, NewType> : unknown
65
65
  )>;
66
+
67
+ export {};
@@ -81,3 +81,5 @@ type SetNonNullableDeepSinglePath<BaseType, KeyPath> =
81
81
  : BaseType[Key];
82
82
  }
83
83
  : Simplify<SetNonNullable<BaseType, (KeyPath | StringToNumber<KeyPath & string>) & keyof BaseType>>;
84
+
85
+ export {};
@@ -37,3 +37,5 @@ export type SetNonNullable<BaseType, Keys extends keyof BaseType = keyof BaseTyp
37
37
  ? NonNullable<BaseType[Key]>
38
38
  : BaseType[Key];
39
39
  };
40
+
41
+ export {};
@@ -42,3 +42,5 @@ type _SetOptional<BaseType, Keys extends keyof BaseType> =
42
42
  Partial<HomomorphicPick<BaseType, Keys>>
43
43
  >
44
44
  : never;
45
+
46
+ export {};
@@ -115,3 +115,5 @@ export type SetParameterType<Function_ extends (...arguments_: any[]) => unknown
115
115
  : (this: ThisArgument, ...arguments_: MergeObjectToArray<Arguments, P>) => ReturnType<Function_>
116
116
  )
117
117
  : Function_; // This part should be unreachable
118
+
119
+ export {};
@@ -40,3 +40,5 @@ export type _SetReadonly<BaseType, Keys extends keyof BaseType> =
40
40
  Readonly<HomomorphicPick<BaseType, Keys>>
41
41
  >
42
42
  : never;
43
+
44
+ export {};
@@ -66,3 +66,5 @@ type SetRequiredDeepSinglePath<BaseType, KeyPath> = BaseType extends NonRecursiv
66
66
  : BaseType[Key];
67
67
  }
68
68
  : SetRequired<BaseType, (KeyPath | StringToNumber<KeyPath & string>) & keyof BaseType>;
69
+
70
+ export {};
@@ -75,3 +75,5 @@ type SetArrayRequired<
75
75
  : SetArrayRequired<Rest, Keys, [...Counter, any], [...Accumulator, TArray[0]]>
76
76
  : never // Should never happen, since `[(infer F)?, ...infer R]` is a top-type for arrays.
77
77
  : never; // Should never happen
78
+
79
+ export {};
@@ -27,3 +27,5 @@ export type SetReturnType<Function_ extends (...arguments_: any[]) => any, TypeT
27
27
  // This part should be unreachable, but we make it meaningful just in case…
28
28
  (...arguments_: Parameters<Function_>) => TypeToReturn
29
29
  );
30
+
31
+ export {};
@@ -176,3 +176,5 @@ type InternalSharedArrayUnionFieldsDeep<
176
176
  Union, Options,
177
177
  [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
178
178
  >;
179
+
180
+ export {};
@@ -75,3 +75,5 @@ Extract<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<un
75
75
  : Simplify<Pick<RelevantMembers, keyof RelevantMembers>>)
76
76
  : never
77
77
  : never;
78
+
79
+ export {};
@@ -113,3 +113,5 @@ export type SimplifyDeep<Type, ExcludeType = never> =
113
113
  ExcludeType | NonRecursiveType | Set<unknown> | Map<unknown, unknown>,
114
114
  object
115
115
  >;
116
+
117
+ export {};
@@ -56,3 +56,5 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
56
56
  @category Object
57
57
  */
58
58
  export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
59
+
60
+ export {};
@@ -28,3 +28,5 @@ export type SingleKeyObject<ObjectType> =
28
28
  IsUnion<keyof ObjectType> extends true
29
29
  ? never
30
30
  : If<IsEmptyObject<ObjectType>, never, ObjectType>;
31
+
32
+ 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
 
@@ -42,4 +42,6 @@ const dbResult: SnakeCasedProperties<ModelProps> = {
42
42
  export type SnakeCase<
43
43
  Value,
44
44
  Options extends WordsOptions = {},
45
- > = DelimiterCase<Value, '_', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
45
+ > = DelimiterCase<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
46
+
47
+ export {};
@@ -1,4 +1,4 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
1
+ import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
2
  import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep.d.ts';
3
3
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
@@ -60,4 +60,6 @@ const splitOnNumbers: SnakeCasedPropertiesDeep<{line1: { line2: [{ line3: string
60
60
  export type SnakeCasedPropertiesDeep<
61
61
  Value,
62
62
  Options extends WordsOptions = {},
63
- > = DelimiterCasedPropertiesDeep<Value, '_', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
63
+ > = DelimiterCasedPropertiesDeep<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
64
+
65
+ export {};
@@ -1,4 +1,4 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
1
+ import type {_DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
2
  import type {DelimiterCasedProperties} from './delimiter-cased-properties.d.ts';
3
3
  import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
@@ -37,4 +37,6 @@ const splitOnNumbers: SnakeCasedProperties<{line1: string}, {splitOnNumbers: tru
37
37
  export type SnakeCasedProperties<
38
38
  Value,
39
39
  Options extends WordsOptions = {},
40
- > = DelimiterCasedProperties<Value, '_', ApplyDefaultOptions<WordsOptions, DefaultDelimiterCaseOptions, Options>>;
40
+ > = DelimiterCasedProperties<Value, '_', ApplyDefaultOptions<WordsOptions, _DefaultDelimiterCaseOptions, Options>>;
41
+
42
+ export {};
@@ -0,0 +1,106 @@
1
+ import type {IfNotAnyOrNever, IsExactOptionalPropertyTypesEnabled} from './internal/type.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/object.d.ts';
3
+ import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';
4
+ import type {IsArrayReadonly} from './internal/array.d.ts';
5
+ import type {UnknownArray} from './unknown-array.d.ts';
6
+ import type {If} from './if.d.ts';
7
+
8
+ /**
9
+ {@link SplitOnRestElement} options.
10
+ */
11
+ type SplitOnRestElementOptions = {
12
+ /**
13
+ Whether to preserve the optional modifier (`?`).
14
+
15
+ - When set to `true`, the optional modifiers are preserved as-is. For example:
16
+ `SplitOnRestElement<[number, string?, ...boolean[]], {preserveOptionalModifier: true}>` returns `[[number, string?], boolean[], []]`.
17
+
18
+ - When set to `false`, optional elements like `T?` are transformed to `T | undefined` or simply `T` depending on the `exactOptionalPropertyTypes` compiler option. For example:
19
+ - With `exactOptionalPropertyTypes` enabled: `SplitOnRestElement<[number, string?, ...boolean[]], {preserveOptionalModifier: false}>` returns `[[number, string], boolean[], []]`
20
+ - And, with it disabled, the result is: `[[number, string | undefined], boolean[], []]`
21
+
22
+ @default true
23
+ */
24
+ preserveOptionalModifier?: boolean;
25
+ };
26
+
27
+ type DefaultSplitOnRestElementOptions = {
28
+ preserveOptionalModifier: true;
29
+ };
30
+
31
+ /**
32
+ 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.
33
+
34
+ Note: If any of the parts are missing, then they will be represented as empty arrays. For example, `SplitOnRestElement<[string, number]>` returns `[[string, number], [], []]`, where parts corresponding to the rest element and elements after it are empty.
35
+
36
+ By default, the optional modifier (`?`) is preserved.
37
+ See {@link SplitOnRestElementOptions `SplitOnRestElementOptions`}.
38
+
39
+ @example
40
+ ```ts
41
+ import type {SplitOnRestElement} from 'type-fest';
42
+
43
+ type T1 = SplitOnRestElement<[number, ...string[], boolean]>;
44
+ //=> [[number], string[], [boolean]]
45
+
46
+ type T2 = SplitOnRestElement<readonly [...boolean[], string]>;
47
+ //=> readonly [[], boolean[], [string]]
48
+
49
+ type T3 = SplitOnRestElement<[number, string?]>;
50
+ //=> [[number, string?], [], []]
51
+
52
+ type T4 = SplitOnRestElement<[number, string?], {preserveOptionalModifier: false}>;
53
+ //=> [[number, string], [], []] or [[number, string | undefined], [], []]
54
+
55
+ type T5 = SplitOnRestElement<readonly [string?, ...number[]], {preserveOptionalModifier: false}>;
56
+ //=> readonly [[string], number[], []] or readonly [[string | undefined], number[], []]
57
+ ```
58
+
59
+ @see ExtractRestElement
60
+ @see ExcludeRestElement
61
+ @category Array
62
+ */
63
+ export type SplitOnRestElement<
64
+ Array_ extends UnknownArray,
65
+ Options extends SplitOnRestElementOptions = {},
66
+ > =
67
+ Array_ extends unknown // For distributing `Array_`
68
+ ? IfNotAnyOrNever<Array_, _SplitOnRestElement<
69
+ Array_,
70
+ ApplyDefaultOptions<SplitOnRestElementOptions, DefaultSplitOnRestElementOptions, Options>
71
+ >> extends infer Result extends UnknownArray
72
+ ? If<IsArrayReadonly<Array_>, Readonly<Result>, Result>
73
+ : never // Should never happen
74
+ : never; // Should never happen
75
+
76
+ /**
77
+ Deconstructs an array on its rest element and returns the split portions.
78
+ */
79
+ export type _SplitOnRestElement<
80
+ Array_ extends UnknownArray,
81
+ Options extends Required<SplitOnRestElementOptions>,
82
+ HeadAcc extends UnknownArray = [],
83
+ TailAcc extends UnknownArray = [],
84
+ > =
85
+ keyof Array_ & `${number}` extends never
86
+ // Enters this branch, if `Array_` is empty (e.g., []),
87
+ // or `Array_` contains no non-rest elements preceding the rest element (e.g., `[...string[]]` or `[...string[], string]`).
88
+ ? Array_ extends readonly [...infer Rest, infer Last]
89
+ ? _SplitOnRestElement<Rest, Options, HeadAcc, [Last, ...TailAcc]> // Accumulate elements that are present after the rest element.
90
+ : [HeadAcc, Array_ extends readonly [] ? [] : Array_, TailAcc] // Add the rest element between the accumulated elements.
91
+ : Array_ extends readonly [(infer First)?, ...infer Rest]
92
+ ? _SplitOnRestElement<
93
+ Rest, Options,
94
+ [
95
+ ...HeadAcc,
96
+ ...IsOptionalKeyOf<Array_, '0'> extends true
97
+ ? Options['preserveOptionalModifier'] extends false
98
+ ? [If<IsExactOptionalPropertyTypesEnabled, First, First | undefined>] // Add `| undefined` for optional elements, if `exactOptionalPropertyTypes` is disabled.
99
+ : [First?]
100
+ : [First],
101
+ ],
102
+ TailAcc
103
+ > // Accumulate elements that are present before the rest element.
104
+ : never; // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
105
+
106
+ export {};
package/source/split.d.ts CHANGED
@@ -8,7 +8,7 @@ Split options.
8
8
 
9
9
  @see {@link Split}
10
10
  */
11
- type SplitOptions = {
11
+ export type SplitOptions = {
12
12
  /**
13
13
  When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
14
14
 
@@ -86,3 +86,5 @@ type SplitHelper<
86
86
  : string[]
87
87
  : never // Should never happen
88
88
  : never; // Should never happen
89
+
90
+ export {};
@@ -82,3 +82,5 @@ export type Spread<
82
82
  ? SpreadTupleOrArray<FirstType, SecondType>
83
83
  : Simplify<SpreadObject<FirstType, SecondType>>
84
84
  : Simplify<SpreadObject<FirstType, SecondType>>;
85
+
86
+ export {};
@@ -45,3 +45,5 @@ type StringRepeatHelper<
45
45
  : IsNumericLiteral<Count> extends false
46
46
  ? string
47
47
  : StringRepeatHelper<Input, Count, [...Counter, never], `${Accumulator}${Input}`>;
48
+
49
+ export {};
@@ -35,3 +35,5 @@ export type StringSlice<
35
35
  : ArraySlice<StringToArray<S>, Start, End> extends infer R extends readonly string[]
36
36
  ? Join<R, ''>
37
37
  : never;
38
+
39
+ export {};
@@ -21,3 +21,5 @@ const carForm: Stringified<Car> = {
21
21
  @category Object
22
22
  */
23
23
  export type Stringified<ObjectType> = {[KeyType in keyof ObjectType]: string};
24
+
25
+ export {};
@@ -90,3 +90,5 @@ structuredClone(good);
90
90
  @category Structured clone
91
91
  */
92
92
  export type StructuredCloneable = StructuredCloneablePrimitive | StructuredCloneableData | StructuredCloneableCollection;
93
+
94
+ export {};
@@ -1,6 +1,7 @@
1
- import type {NumberAbsolute, BuildTuple, ReverseSign} from './internal/index.d.ts';
1
+ import type {NumberAbsolute, ReverseSign} from './internal/index.d.ts';
2
2
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
3
3
  import type {LessThan} from './less-than.d.ts';
4
+ import type {TupleOf} from './tuple-of.d.ts';
4
5
 
5
6
  /**
6
7
  Returns the difference between two numbers.
@@ -60,7 +61,7 @@ type SubtractPostChecks<A extends number, B extends number, AreNegative = [IsNeg
60
61
  // When both numbers are negative we subtract the absolute values and then reverse the sign
61
62
  ? ReverseSign<SubtractPositives<NumberAbsolute<A>, NumberAbsolute<B>>>
62
63
  // When the signs are different we can add the absolute values and then reverse the sign if A < B
63
- : [...BuildTuple<NumberAbsolute<A>>, ...BuildTuple<NumberAbsolute<B>>] extends infer R extends unknown[]
64
+ : [...TupleOf<NumberAbsolute<A>>, ...TupleOf<NumberAbsolute<B>>] extends infer R extends unknown[]
64
65
  ? LessThan<A, B> extends true ? ReverseSign<R['length']> : R['length']
65
66
  : never;
66
67
 
@@ -78,6 +79,8 @@ Subtracts two positive numbers A and B such that A > B.
78
79
  */
79
80
  type SubtractIfAGreaterThanB<A extends number, B extends number> =
80
81
  // This is where we always want to end up and do the actual subtraction
81
- BuildTuple<A> extends [...BuildTuple<B>, ...infer R]
82
+ TupleOf<A> extends [...TupleOf<B>, ...infer R]
82
83
  ? R['length']
83
84
  : never;
85
+
86
+ export {};
package/source/sum.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type {NumberAbsolute, BuildTuple, TupleMax, ReverseSign} from './internal/index.d.ts';
1
+ import type {TupleOf} from './tuple-of.d.ts';
2
+ import type {NumberAbsolute, TupleMax, ReverseSign} from './internal/index.d.ts';
2
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
3
4
  import type {Subtract} from './subtract.d.ts';
4
5
 
@@ -73,6 +74,8 @@ type SumPostChecks<A extends number, B extends number, AreNegative = [IsNegative
73
74
  Adds two positive numbers.
74
75
  */
75
76
  type SumPositives<A extends number, B extends number> =
76
- [...BuildTuple<A>, ...BuildTuple<B>]['length'] extends infer Result extends number
77
+ [...TupleOf<A>, ...TupleOf<B>]['length'] extends infer Result extends number
77
78
  ? Result
78
79
  : never;
80
+
81
+ export {};
@@ -49,3 +49,5 @@ export type TaggedUnion<
49
49
  > = {
50
50
  [Name in keyof UnionMembers]: {[Key in TagKey]: Name} & UnionMembers[Name];
51
51
  }[keyof UnionMembers];
52
+
53
+ export {};
@@ -1,5 +1,6 @@
1
1
  import type tag from 'tagged-tag';
2
2
 
3
+ // eslint-disable-next-line type-fest/require-exported-types
3
4
  export type TagContainer<Token> = {
4
5
  readonly [tag]: Token;
5
6
  };
@@ -256,3 +257,5 @@ export type UnwrapOpaque<OpaqueType extends TagContainer<unknown>> =
256
257
  : OpaqueType;
257
258
 
258
259
  export {type default as tag} from 'tagged-tag';
260
+
261
+ export {};
package/source/trim.d.ts CHANGED
@@ -25,3 +25,5 @@ Trim<' foo '>
25
25
  @category Template literal
26
26
  */
27
27
  export type Trim<V extends string> = TrimLeft<TrimRight<V>>;
28
+
29
+ export {};