type-fest 5.0.1 → 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 +5 -0
  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
@@ -1,43 +1,89 @@
1
+ import type {Except} from './except.d.ts';
2
+ import type {TupleOf} from './tuple-of.d.ts';
3
+
1
4
  /**
2
5
  Methods to exclude.
3
6
  */
4
7
  type ArrayLengthMutationKeys = 'splice' | 'push' | 'pop' | 'shift' | 'unshift';
5
8
 
6
9
  /**
7
- Create a type that represents an array of the given type and length. The array's length and the `Array` prototype methods that manipulate its length are excluded in the resulting type.
10
+ 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.
11
+
12
+ The problem with the built-in tuple type is that it allows mutating methods like `push`, `pop` etc, which can cause issues, like in the following example:
13
+
14
+ @example
15
+ ```
16
+ const color: [number, number, number] = [255, 128, 64];
17
+
18
+ function toHex([r, g, b]: readonly [number, number, number]) {
19
+ return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`;
20
+ }
21
+
22
+ color.pop(); // Allowed
23
+
24
+ console.log(toHex(color)); // Compiles fine, but fails at runtime since index `2` no longer contains a `number`.
25
+ ```
26
+
27
+ `ArrayLengthMutationKeys` solves this problem by excluding methods like `push`, `pop` etc from the resulting type.
28
+
29
+ @example
30
+ ```
31
+ import type {FixedLengthArray} from 'type-fest';
32
+
33
+ const color: FixedLengthArray<number, 3> = [255, 128, 64];
8
34
 
9
- Please participate in [this issue](https://github.com/microsoft/TypeScript/issues/26223) if you want to have a similar type built into TypeScript.
35
+ color.pop();
36
+ //=> Error: Property 'pop' does not exist on type 'FixedLengthArray<number, 3>'.
37
+ ```
10
38
 
11
39
  Use-cases:
12
40
  - Declaring fixed-length tuples or arrays with a large number of items.
13
- - Creating a range union (for example, `0 | 1 | 2 | 3 | 4` from the keys of such a type) without having to resort to recursive types.
14
41
  - Creating an array of coordinates with a static length, for example, length of 3 for a 3D vector.
15
42
 
16
- Note: This type does not prevent out-of-bounds access. Prefer `ReadonlyTuple` unless you need mutability.
17
-
18
43
  @example
19
44
  ```
20
- import type {FixedLengthArray} from 'type-fest';
45
+ let color: FixedLengthArray<number, 3> = [255, 128, 64];
21
46
 
22
- type FencingTeam = FixedLengthArray<string, 3>;
47
+ const red = color[0];
48
+ //=> number
49
+ const green = color[1];
50
+ //=> number
51
+ const blue = color[2];
52
+ //=> number
23
53
 
24
- const guestFencingTeam: FencingTeam = ['Josh', 'Michael', 'Robert'];
54
+ const alpha = color[3];
55
+ //=> Error: Property '3' does not exist on type 'FixedLengthArray<number, 3>'.
25
56
 
26
- const homeFencingTeam: FencingTeam = ['George', 'John'];
27
- //=> error TS2322: Type string[] is not assignable to type 'FencingTeam'
57
+ // You can write to valid indices.
58
+ color[0] = 128;
59
+ color[1] = 64;
60
+ color[2] = 32;
28
61
 
29
- guestFencingTeam.push('Sam');
30
- //=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
62
+ // But you cannot write to out-of-bounds indices.
63
+ color[3] = 0.5;
64
+ //=> Error: Property '3' does not exist on type 'FixedLengthArray<number, 3>'.
65
+
66
+ color.push(0.5);
67
+ //=> Error: Property 'push' does not exist on type 'FixedLengthArray<number, 3>'.
68
+
69
+ color = [0, 128, 255, 0.5];
70
+ //=> Error: Type '[number, number, number, number]' is not assignable to type 'FixedLengthArray<number, 3>'. Types of property 'length' are incompatible.
71
+
72
+ color.length = 4;
73
+ //=> Error: Cannot assign to 'length' because it is a read-only property.
74
+
75
+ function toHex([r, g, b]: readonly [number, number, number]) {
76
+ return `#${r.toString(16)}${g.toString(16)}${b.toString(16)}`;
77
+ }
78
+
79
+ console.log(toHex(color)); // `FixedLengthArray<number, 3>` is assignable to `readonly [number, number, number]`.
31
80
  ```
32
81
 
33
82
  @category Array
34
- @see ReadonlyTuple
35
83
  */
36
- export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
37
- ArrayPrototype,
38
- Exclude<keyof ArrayPrototype, ArrayLengthMutationKeys>
39
- > & {
40
- [index: number]: Element;
41
- [Symbol.iterator]: () => IterableIterator<Element>;
42
- readonly length: Length;
43
- };
84
+ export type FixedLengthArray<Element, Length extends number> =
85
+ Except<TupleOf<Length, Element>, ArrayLengthMutationKeys | number | 'length'>
86
+ & {readonly length: Length}
87
+ & (number extends Length ? {[n: number]: Element} : {}); // Add `number` index signature only for non-tuple arrays.
88
+
89
+ export {};
package/source/get.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type {ApplyDefaultOptions, ToString} from './internal/index.d.ts';
2
- import type {LiteralStringUnion} from './literal-union.d.ts';
2
+ import type {_LiteralStringUnion} from './literal-union.d.ts';
3
3
  import type {Paths} from './paths.d.ts';
4
4
  import type {Split} from './split.d.ts';
5
5
  import type {KeyAsString} from './key-as-string.d.ts';
6
6
  import type {DigitCharacter} from './characters.d.ts';
7
7
 
8
- type GetOptions = {
8
+ export type GetOptions = {
9
9
  /**
10
10
  Include `undefined` in the return type when accessing properties.
11
11
 
@@ -210,7 +210,7 @@ export type Get<
210
210
  BaseType,
211
211
  Path extends
212
212
  | readonly string[]
213
- | LiteralStringUnion<ToString<Paths<BaseType, {bracketNotation: false; maxRecursionDepth: 2}> | Paths<BaseType, {bracketNotation: true; maxRecursionDepth: 2}>>>,
213
+ | _LiteralStringUnion<ToString<Paths<BaseType, {bracketNotation: false; maxRecursionDepth: 2}> | Paths<BaseType, {bracketNotation: true; maxRecursionDepth: 2}>>>,
214
214
  Options extends GetOptions = {},
215
215
  > =
216
216
  GetWithPath<
@@ -218,3 +218,5 @@ export type Get<
218
218
  Path extends string ? ToPath<Path> : Path,
219
219
  ApplyDefaultOptions<GetOptions, DefaultGetOptions, Options>
220
220
  >;
221
+
222
+ export {};
@@ -19,3 +19,5 @@ type ExtraGlobals = GlobalThis & {
19
19
  @category Type
20
20
  */
21
21
  export type GlobalThis = typeof globalThis;
22
+
23
+ export {};
@@ -1 +1,3 @@
1
1
  export type * from './observable-like.d.ts';
2
+
3
+ export {};
@@ -16,6 +16,7 @@ As well, some guidance on making an `Observable` to not include `closed` propert
16
16
 
17
17
  @category Observable
18
18
  */
19
+ // eslint-disable-next-line type-fest/require-exported-types
19
20
  export type Unsubscribable = {
20
21
  unsubscribe(): void;
21
22
  };
@@ -38,6 +39,7 @@ type OnComplete = () => void;
38
39
  /**
39
40
  @category Observable
40
41
  */
42
+ // eslint-disable-next-line type-fest/require-exported-types
41
43
  export type Observer<ValueType> = {
42
44
  next: OnNext<ValueType>;
43
45
  error: OnError;
@@ -67,7 +69,10 @@ But `Observable` implementations have evolved to preferring case 2 and some impl
67
69
 
68
70
  @category Observable
69
71
  */
72
+ // eslint-disable-next-line type-fest/require-exported-types
70
73
  export type ObservableLike<ValueType = unknown> = {
71
74
  subscribe(observer?: Partial<Observer<ValueType>>): Unsubscribable;
72
75
  [Symbol.observable](): ObservableLike<ValueType>;
73
76
  };
77
+
78
+ export {};
@@ -20,3 +20,5 @@ GreaterThanOrEqual<1, 5>;
20
20
  export type GreaterThanOrEqual<A extends number, B extends number> = number extends A | B
21
21
  ? never
22
22
  : A extends B ? true : GreaterThan<A, B>;
23
+
24
+ export {};
@@ -54,3 +54,5 @@ export type GreaterThan<A extends number, B extends number> =
54
54
  : never
55
55
  : never // Should never happen
56
56
  : never; // Should never happen
57
+
58
+ export {};
@@ -19,3 +19,5 @@ type UpdateService<Entity extends object> = {
19
19
  @category Utilities
20
20
  */
21
21
  export type HasOptionalKeys<BaseType extends object> = OptionalKeysOf<BaseType> extends never ? false : true;
22
+
23
+ export {};
@@ -19,3 +19,5 @@ type UpdateService<Entity extends object> = {
19
19
  @category Utilities
20
20
  */
21
21
  export type HasReadonlyKeys<BaseType extends object> = ReadonlyKeysOf<BaseType> extends never ? false : true;
22
+
23
+ export {};
@@ -57,3 +57,5 @@ const optD: Options2 = {
57
57
  @category Utilities
58
58
  */
59
59
  export type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
60
+
61
+ export {};
@@ -19,3 +19,5 @@ type UpdateService<Entity extends object> = {
19
19
  @category Utilities
20
20
  */
21
21
  export type HasWritableKeys<BaseType extends object> = WritableKeysOf<BaseType> extends never ? false : true;
22
+
23
+ export {};
@@ -24,3 +24,5 @@ type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
24
24
  export type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
25
25
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
26
26
  );
27
+
28
+ export {};
@@ -26,3 +26,5 @@ export type IfEmptyObject<
26
26
  TypeIfEmptyObject = true,
27
27
  TypeIfNotEmptyObject = false,
28
28
  > = IsEmptyObject<T> extends true ? TypeIfEmptyObject : TypeIfNotEmptyObject;
29
+
30
+ export {};
@@ -24,3 +24,5 @@ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
24
24
  export type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
25
25
  IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
26
26
  );
27
+
28
+ export {};
@@ -24,3 +24,5 @@ type ShouldBeBar = IfNull<'not null', 'foo', 'bar'>;
24
24
  export type IfNull<T, TypeIfNull = true, TypeIfNotNull = false> = (
25
25
  IsNull<T> extends true ? TypeIfNull : TypeIfNotNull
26
26
  );
27
+
28
+ export {};
@@ -24,3 +24,5 @@ type ShouldBeBar = IfUnknown<'not unknown', 'foo', 'bar'>;
24
24
  export type IfUnknown<T, TypeIfUnknown = true, TypeIfNotUnknown = false> = (
25
25
  IsUnknown<T> extends true ? TypeIfUnknown : TypeIfNotUnknown
26
26
  );
27
+
28
+ export {};
package/source/if.d.ts CHANGED
@@ -63,3 +63,5 @@ export type If<Type extends boolean, IfBranch, ElseBranch> =
63
63
  : Type extends true
64
64
  ? IfBranch
65
65
  : ElseBranch;
66
+
67
+ export {};
@@ -20,3 +20,5 @@ export type Includes<Value extends readonly any[], Item> =
20
20
  ? true
21
21
  : Includes<rest, Item>
22
22
  : false;
23
+
24
+ export {};
@@ -33,3 +33,5 @@ type Hundreds = IntClosedRange<100, 900, 100>;
33
33
  @see IntRange
34
34
  */
35
35
  export type IntClosedRange<Start extends number, End extends number, Skip extends number = 1> = IntRange<Start, Sum<End, 1>, Skip>;
36
+
37
+ export {};
@@ -1,4 +1,4 @@
1
- import type {BuildTuple} from './internal/index.d.ts';
1
+ import type {TupleOf} from './tuple-of.d.ts';
2
2
  import type {Subtract} from './subtract.d.ts';
3
3
 
4
4
  /**
@@ -44,14 +44,16 @@ type PrivateIntRange<
44
44
  // The gap between each number, gap = step - 1
45
45
  Gap extends number = Subtract<Step, 1>,
46
46
  // The final `List` is `[...StartLengthTuple, ...[number, ...GapLengthTuple], ...[number, ...GapLengthTuple], ... ...]`, so can initialize the `List` with `[...StartLengthTuple]`
47
- List extends unknown[] = BuildTuple<Start, never>,
48
- EndLengthTuple extends unknown[] = BuildTuple<End>,
47
+ List extends unknown[] = TupleOf<Start, never>,
48
+ EndLengthTuple extends unknown[] = TupleOf<End>,
49
49
  > = Gap extends 0 ?
50
50
  // Handle the case that without `Step`
51
51
  List['length'] extends End // The result of "List[length] === End"
52
52
  ? Exclude<List[number], never> // All unused elements are `never`, so exclude them
53
53
  : PrivateIntRange<Start, End, Step, Gap, [...List, List['length'] ]>
54
54
  // Handle the case that with `Step`
55
- : List extends [...(infer U), ...EndLengthTuple] // The result of "List[length] >= End", because the `...BuildTuple<Gap, never>` maybe make `List` too long.
55
+ : List extends [...(infer U), ...EndLengthTuple] // The result of "List[length] >= End", because the `...TupleOf<Gap, never>` maybe make `List` too long.
56
56
  ? Exclude<List[number], never>
57
- : PrivateIntRange<Start, End, Step, Gap, [...List, List['length'], ...BuildTuple<Gap, never>]>;
57
+ : PrivateIntRange<Start, End, Step, Gap, [...List, List['length'], ...TupleOf<Gap, never>]>;
58
+
59
+ export {};
@@ -156,3 +156,5 @@ type _CollapseRestElement<
156
156
  >
157
157
  : never // Should never happen, since `[(infer First)?, ...infer Rest]` is a top-type for arrays.
158
158
  : never; // Should never happen
159
+
160
+ export {};
@@ -61,3 +61,5 @@ export type AsciiPunctuation =
61
61
  | '|'
62
62
  | '}'
63
63
  | '~';
64
+
65
+ export {};
@@ -1,4 +1,4 @@
1
- import type {Simplify} from './simplify.d.ts';
1
+ import type {Simplify} from '../simplify.d.ts';
2
2
 
3
3
  // Returns `never` if the key is optional otherwise return the key type.
4
4
  type RequiredFilter<Type, Key extends keyof Type> = undefined extends Type[Key]
@@ -45,3 +45,5 @@ export type EnforceOptional<ObjectType> = Simplify<{
45
45
  } & {
46
46
  [Key in keyof ObjectType as OptionalFilter<ObjectType, Key>]?: Exclude<ObjectType[Key], undefined>
47
47
  }>;
48
+
49
+ export {};
@@ -6,3 +6,6 @@ export type * from './object.d.ts';
6
6
  export type * from './string.d.ts';
7
7
  export type * from './tuple.d.ts';
8
8
  export type * from './type.d.ts';
9
+ export type * from './enforce-optional.d.ts';
10
+
11
+ export {};
@@ -96,3 +96,5 @@ Key extends keyof T
96
96
  ? NumberKey
97
97
  : never
98
98
  : never;
99
+
100
+ export {};
@@ -146,3 +146,5 @@ export type ReverseSign<N extends number> =
146
146
  `${N}` extends `-${infer P extends number}` ? P
147
147
  // Handle positive numbers
148
148
  : `-${N}` extends `${infer R extends number}` ? R : never;
149
+
150
+ export {};
@@ -263,3 +263,5 @@ export type CollapseLiterals<T> = {} extends T
263
263
  : T extends infer U & {}
264
264
  ? U
265
265
  : T;
266
+
267
+ export {};
@@ -1,7 +1,7 @@
1
+ import type {TupleOf} from '../tuple-of.d.ts';
1
2
  import type {NegativeInfinity, PositiveInfinity} from '../numeric.d.ts';
2
3
  import type {Trim} from '../trim.d.ts';
3
4
  import type {Whitespace} from './characters.d.ts';
4
- import type {BuildTuple} from './tuple.d.ts';
5
5
 
6
6
  /**
7
7
  Return a string representation of the given string or number.
@@ -171,7 +171,7 @@ PositiveNumericStringGt<'1', '500'>;
171
171
  */
172
172
  export type PositiveNumericStringGt<A extends string, B extends string> = A extends B
173
173
  ? false
174
- : [BuildTuple<StringLength<A>, 0>, BuildTuple<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]]
174
+ : [TupleOf<StringLength<A>, 0>, TupleOf<StringLength<B>, 0>] extends infer R extends [readonly unknown[], readonly unknown[]]
175
175
  ? R[0] extends [...R[1], ...infer Remain extends readonly unknown[]]
176
176
  ? 0 extends Remain['length']
177
177
  ? SameLengthPositiveNumericStringGt<A, B>
@@ -198,3 +198,5 @@ type PositiveNumericCharacterGt<A extends string, B extends string> = NumericStr
198
198
  : false
199
199
  : never
200
200
  : never;
201
+
202
+ export {};
@@ -30,19 +30,6 @@ export type TupleLength<T extends UnknownArray> =
30
30
  : T['length']
31
31
  : never; // Should never happen
32
32
 
33
- /**
34
- Create a tuple type of the given length `<L>` and fill it with the given type `<Fill>`.
35
-
36
- If `<Fill>` is not provided, it will default to `unknown`.
37
-
38
- @link https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
39
- */
40
- export type BuildTuple<L extends number, Fill = unknown, T extends readonly unknown[] = []> = number extends L
41
- ? Fill[]
42
- : L extends T['length']
43
- ? T
44
- : BuildTuple<L, Fill, [...T, Fill]>;
45
-
46
33
  /**
47
34
  Returns the maximum value from a tuple of integers.
48
35
 
@@ -88,3 +75,5 @@ export type TupleMin<A extends number[], Result extends number = PositiveInfinit
88
75
  ? TupleMin<R, F>
89
76
  : TupleMin<R, Result>
90
77
  : Result;
78
+
79
+ export {};
@@ -128,3 +128,5 @@ Indicates the value of `exactOptionalPropertyTypes` compiler option.
128
128
  export type IsExactOptionalPropertyTypesEnabled = [(string | undefined)?] extends [string?]
129
129
  ? false
130
130
  : true;
131
+
132
+ export {};
@@ -74,3 +74,5 @@ keyOfInvariantFooBar(invariantOf(fooBarBaz)); // Error: Argument of type 'Invari
74
74
  @category Type
75
75
  */
76
76
  export type InvariantOf<Type> = Type & {[invariantBrand]: (_: Type) => Type};
77
+
78
+ export {};
@@ -27,3 +27,5 @@ const anyA = get(anyObject, 'a');
27
27
  @category Utilities
28
28
  */
29
29
  export type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
30
+
31
+ export {};
@@ -1,3 +1,4 @@
1
+ import type {IsNever} from './is-never.d.ts';
1
2
  /**
2
3
  Returns a boolean for whether the two given types are equal.
3
4
 
@@ -25,7 +26,21 @@ type Includes<Value extends readonly any[], Item> =
25
26
  @category Utilities
26
27
  */
27
28
  export type IsEqual<A, B> =
29
+ [A, B] extends [infer AA, infer BB]
30
+ ? [AA] extends [never]
31
+ ? [BB] extends [never]
32
+ ? true
33
+ : false
34
+ : [BB] extends [never]
35
+ ? false
36
+ : _IsEqual<AA, BB>
37
+ : false;
38
+
39
+ // This version fails the `equalWrappedTupleIntersectionToBeNeverAndNeverExpanded` test in `test-d/is-equal.ts`.
40
+ type _IsEqual<A, B> =
28
41
  (<G>() => G extends A & G | G ? 1 : 2) extends
29
42
  (<G>() => G extends B & G | G ? 1 : 2)
30
43
  ? true
31
44
  : false;
45
+
46
+ export {};
@@ -39,3 +39,5 @@ export type IsFloat<T> = T extends number
39
39
  ? true
40
40
  : false
41
41
  : false;
42
+
43
+ export {};
@@ -56,3 +56,5 @@ T extends bigint
56
56
  ? false
57
57
  : Not<IsFloat<T>>
58
58
  : false;
59
+
60
+ export {};
@@ -1,5 +1,5 @@
1
1
  import type {Primitive} from './primitive.d.ts';
2
- import type {Numeric} from './numeric.d.ts';
2
+ import type {_Numeric} from './numeric.d.ts';
3
3
  import type {CollapseLiterals, IfNotAnyOrNever, IsNotFalse, IsPrimitive} from './internal/index.d.ts';
4
4
  import type {IsNever} from './is-never.d.ts';
5
5
  import type {TagContainer, UnwrapTagged} from './tagged.d.ts';
@@ -173,7 +173,7 @@ endsWith('abc123', end);
173
173
  @category Type Guard
174
174
  @category Utilities
175
175
  */
176
- export type IsNumericLiteral<T> = LiteralChecks<T, Numeric>;
176
+ export type IsNumericLiteral<T> = LiteralChecks<T, _Numeric>;
177
177
 
178
178
  /**
179
179
  Returns a boolean for whether the given type is a `true` or `false` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
@@ -310,3 +310,5 @@ export type IsLiteral<T> =
310
310
  IsPrimitive<T> extends true
311
311
  ? IsNotFalse<IsLiteralUnion<T>>
312
312
  : false;
313
+
314
+ export {};
@@ -34,3 +34,5 @@ type IsLowercaseHelper<S extends string> = S extends Lowercase<string>
34
34
  : S extends Uppercase<string> | Capitalize<string> | `${string}${Uppercase<string>}${string}`
35
35
  ? false
36
36
  : boolean;
37
+
38
+ export {};
@@ -40,3 +40,5 @@ endIfEqual('abc', '123');
40
40
  @category Utilities
41
41
  */
42
42
  export type IsNever<T> = [T] extends [never] ? true : false;
43
+
44
+ export {};
@@ -18,3 +18,5 @@ type Example2 = NonNullFallback<number, string>;
18
18
  @category Utilities
19
19
  */
20
20
  export type IsNull<T> = [T] extends [null] ? true : false;
21
+
22
+ export {};
@@ -26,3 +26,5 @@ type D = IsNullable<string | null | undefined>;
26
26
  @category Utilities
27
27
  */
28
28
  export type IsNullable<T> = IsAny<T> extends true ? true : Extract<T, null> extends never ? false : true;
29
+
30
+ export {};
@@ -47,3 +47,5 @@ export type IsOptionalKeyOf<Type extends object, Key extends keyof Type> =
47
47
  ? false
48
48
  : true
49
49
  : false;
50
+
51
+ export {};
@@ -24,3 +24,5 @@ type D = IsOptional<string | null | undefined>;
24
24
  @category Utilities
25
25
  */
26
26
  export type IsOptional<T> = IsAny<T> extends true ? true : Extract<T, undefined> extends never ? false : true;
27
+
28
+ export {};
@@ -51,3 +51,5 @@ export type IsReadonlyKeyOf<Type extends object, Key extends keyof Type> =
51
51
  >
52
52
  : never // Should never happen
53
53
  : never; // Should never happen
54
+
55
+ export {};
@@ -47,3 +47,5 @@ export type IsRequiredKeyOf<Type extends object, Key extends keyof Type> =
47
47
  : Key extends keyof Type
48
48
  ? Not<IsOptionalKeyOf<Type, Key>>
49
49
  : false;
50
+
51
+ export {};
@@ -88,3 +88,5 @@ type _IsTuple<
88
88
  : true
89
89
  : false
90
90
  >>;
91
+
92
+ export {};
@@ -18,3 +18,5 @@ type Example2 = UndefinedFallback<number, string>;
18
18
  @category Utilities
19
19
  */
20
20
  export type IsUndefined<T> = [T] extends [undefined] ? true : false;
21
+
22
+ export {};
@@ -35,3 +35,5 @@ type InternalIsUnion<T, U = T> =
35
35
  ? boolean extends Result ? true
36
36
  : Result
37
37
  : never; // Should never happen
38
+
39
+ export {};
@@ -50,3 +50,5 @@ export type IsUnknown<T> = (
50
50
  : false
51
51
  : false
52
52
  );
53
+
54
+ export {};
@@ -34,3 +34,5 @@ type IsUppercaseHelper<S extends string> = S extends Uppercase<string>
34
34
  : S extends Lowercase<string> | Uncapitalize<string> | `${string}${Lowercase<string>}${string}`
35
35
  ? false
36
36
  : boolean;
37
+
38
+ export {};
@@ -47,3 +47,5 @@ export type IsWritableKeyOf<Type extends object, Key extends keyof Type> =
47
47
  : Key extends keyof Type
48
48
  ? Not<IsReadonlyKeyOf<Type, Key>>
49
49
  : false;
50
+
51
+ export {};
@@ -62,3 +62,5 @@ export type IterableElement<TargetIterable> =
62
62
  TargetIterable extends AsyncIterable<infer ElementType> ?
63
63
  ElementType :
64
64
  never;
65
+
66
+ export {};
package/source/join.d.ts CHANGED
@@ -66,3 +66,5 @@ export type Join<
66
66
  ]
67
67
  ? `${Join<Head, Delimiter>}${Delimiter}${NullishCoalesce<Last, ''>}`
68
68
  : string;
69
+
70
+ export {};
@@ -5,7 +5,7 @@ This type can be useful to enforce some input to be JSON-compatible or as a supe
5
5
 
6
6
  @category JSON
7
7
  */
8
- export type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
8
+ export type JsonObject = {[Key in string]: JsonValue};
9
9
 
10
10
  /**
11
11
  Matches a JSON array.
@@ -29,3 +29,5 @@ Matches any valid JSON value.
29
29
  @category JSON
30
30
  */
31
31
  export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
32
+
33
+ export {};
@@ -35,3 +35,5 @@ JSON.stringify(good);
35
35
  @category JSON
36
36
  */
37
37
  export type Jsonifiable = JsonPrimitive | JsonifiableObject | JsonifiableArray;
38
+
39
+ export {};
@@ -124,3 +124,5 @@ export type Jsonify<T> = IsAny<T> extends true
124
124
  : IsUnknown<T> extends true
125
125
  ? JsonValue
126
126
  : never; // Otherwise any other non-object is removed
127
+
128
+ export {};