@depup/type-fest 5.4.4-depup.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 (201) hide show
  1. package/README.md +25 -0
  2. package/index.d.ts +211 -0
  3. package/license-cc0 +121 -0
  4. package/license-mit +9 -0
  5. package/package.json +85 -0
  6. package/readme.md +1052 -0
  7. package/source/all-extend.d.ts +120 -0
  8. package/source/all-union-fields.d.ts +91 -0
  9. package/source/and.d.ts +81 -0
  10. package/source/array-element.d.ts +46 -0
  11. package/source/array-indices.d.ts +25 -0
  12. package/source/array-reverse.d.ts +84 -0
  13. package/source/array-slice.d.ts +132 -0
  14. package/source/array-splice.d.ts +104 -0
  15. package/source/array-tail.d.ts +70 -0
  16. package/source/array-values.d.ts +24 -0
  17. package/source/arrayable.d.ts +31 -0
  18. package/source/async-return-type.d.ts +28 -0
  19. package/source/asyncify.d.ts +25 -0
  20. package/source/basic.d.ts +38 -0
  21. package/source/camel-case.d.ts +92 -0
  22. package/source/camel-cased-properties-deep.d.ts +99 -0
  23. package/source/camel-cased-properties.d.ts +45 -0
  24. package/source/characters.d.ts +67 -0
  25. package/source/conditional-except.d.ts +47 -0
  26. package/source/conditional-keys.d.ts +63 -0
  27. package/source/conditional-pick-deep.d.ts +120 -0
  28. package/source/conditional-pick.d.ts +46 -0
  29. package/source/conditional-simplify-deep.d.ts +73 -0
  30. package/source/conditional-simplify.d.ts +50 -0
  31. package/source/delimiter-case.d.ts +77 -0
  32. package/source/delimiter-cased-properties-deep.d.ts +108 -0
  33. package/source/delimiter-cased-properties.d.ts +48 -0
  34. package/source/distributed-omit.d.ts +96 -0
  35. package/source/distributed-pick.d.ts +92 -0
  36. package/source/empty-object.d.ts +51 -0
  37. package/source/entries.d.ts +64 -0
  38. package/source/entry.d.ts +67 -0
  39. package/source/exact.d.ts +73 -0
  40. package/source/except.d.ts +112 -0
  41. package/source/exclude-rest-element.d.ts +40 -0
  42. package/source/exclude-strict.d.ts +51 -0
  43. package/source/exclusify-union.d.ts +147 -0
  44. package/source/extends-strict.d.ts +44 -0
  45. package/source/extract-rest-element.d.ts +30 -0
  46. package/source/extract-strict.d.ts +51 -0
  47. package/source/find-global-type.d.ts +68 -0
  48. package/source/fixed-length-array.d.ts +97 -0
  49. package/source/get.d.ts +227 -0
  50. package/source/global-this.d.ts +24 -0
  51. package/source/globals/index.d.ts +3 -0
  52. package/source/globals/observable-like.d.ts +78 -0
  53. package/source/greater-than-or-equal.d.ts +30 -0
  54. package/source/greater-than.d.ts +58 -0
  55. package/source/has-optional-keys.d.ts +23 -0
  56. package/source/has-readonly-keys.d.ts +23 -0
  57. package/source/has-required-keys.d.ts +61 -0
  58. package/source/has-writable-keys.d.ts +23 -0
  59. package/source/if-any.d.ts +28 -0
  60. package/source/if-empty-object.d.ts +30 -0
  61. package/source/if-never.d.ts +28 -0
  62. package/source/if-null.d.ts +28 -0
  63. package/source/if-unknown.d.ts +28 -0
  64. package/source/if.d.ts +102 -0
  65. package/source/includes.d.ts +24 -0
  66. package/source/int-closed-range.d.ts +47 -0
  67. package/source/int-range.d.ts +69 -0
  68. package/source/internal/array.d.ts +151 -0
  69. package/source/internal/characters.d.ts +65 -0
  70. package/source/internal/enforce-optional.d.ts +49 -0
  71. package/source/internal/index.d.ts +11 -0
  72. package/source/internal/keys.d.ts +100 -0
  73. package/source/internal/numeric.d.ts +151 -0
  74. package/source/internal/object.d.ts +292 -0
  75. package/source/internal/string.d.ts +202 -0
  76. package/source/internal/tuple.d.ts +79 -0
  77. package/source/internal/type.d.ts +164 -0
  78. package/source/invariant-of.d.ts +85 -0
  79. package/source/is-any.d.ts +31 -0
  80. package/source/is-equal.d.ts +42 -0
  81. package/source/is-float.d.ts +43 -0
  82. package/source/is-integer.d.ts +60 -0
  83. package/source/is-literal.d.ts +315 -0
  84. package/source/is-lowercase.d.ts +38 -0
  85. package/source/is-never.d.ts +56 -0
  86. package/source/is-null.d.ts +22 -0
  87. package/source/is-nullable.d.ts +30 -0
  88. package/source/is-optional-key-of.d.ts +51 -0
  89. package/source/is-optional.d.ts +28 -0
  90. package/source/is-readonly-key-of.d.ts +55 -0
  91. package/source/is-required-key-of.d.ts +51 -0
  92. package/source/is-tuple.d.ts +92 -0
  93. package/source/is-undefined.d.ts +22 -0
  94. package/source/is-union.d.ts +40 -0
  95. package/source/is-unknown.d.ts +43 -0
  96. package/source/is-uppercase.d.ts +38 -0
  97. package/source/is-writable-key-of.d.ts +51 -0
  98. package/source/iterable-element.d.ts +66 -0
  99. package/source/join.d.ts +79 -0
  100. package/source/json-value.d.ts +33 -0
  101. package/source/jsonifiable.d.ts +37 -0
  102. package/source/jsonify.d.ts +127 -0
  103. package/source/kebab-case.d.ts +46 -0
  104. package/source/kebab-cased-properties-deep.d.ts +65 -0
  105. package/source/kebab-cased-properties.d.ts +42 -0
  106. package/source/key-as-string.d.ts +27 -0
  107. package/source/keys-of-union.d.ts +44 -0
  108. package/source/last-array-element.d.ts +36 -0
  109. package/source/less-than-or-equal.d.ts +24 -0
  110. package/source/less-than.d.ts +28 -0
  111. package/source/literal-to-primitive-deep.d.ts +71 -0
  112. package/source/literal-to-primitive.d.ts +38 -0
  113. package/source/literal-union.d.ts +39 -0
  114. package/source/merge-deep.d.ts +495 -0
  115. package/source/merge-exclusive.d.ts +45 -0
  116. package/source/merge.d.ts +62 -0
  117. package/source/multidimensional-array.d.ts +38 -0
  118. package/source/multidimensional-readonly-array.d.ts +38 -0
  119. package/source/non-empty-object.d.ts +38 -0
  120. package/source/non-empty-string.d.ts +32 -0
  121. package/source/non-empty-tuple.d.ts +24 -0
  122. package/source/numeric.d.ts +226 -0
  123. package/source/object-merge.d.ts +194 -0
  124. package/source/omit-deep.d.ts +154 -0
  125. package/source/omit-index-signature.d.ts +98 -0
  126. package/source/opaque.d.ts +3 -0
  127. package/source/optional-keys-of.d.ts +46 -0
  128. package/source/or.d.ts +89 -0
  129. package/source/override-properties.d.ts +43 -0
  130. package/source/package-json.d.ts +710 -0
  131. package/source/partial-deep.d.ts +155 -0
  132. package/source/partial-on-undefined-deep.d.ts +81 -0
  133. package/source/pascal-case.d.ts +51 -0
  134. package/source/pascal-cased-properties-deep.d.ts +72 -0
  135. package/source/pascal-cased-properties.d.ts +42 -0
  136. package/source/paths.d.ts +241 -0
  137. package/source/pick-deep.d.ts +152 -0
  138. package/source/pick-index-signature.d.ts +52 -0
  139. package/source/primitive.d.ts +15 -0
  140. package/source/promisable.d.ts +27 -0
  141. package/source/readonly-deep.d.ts +116 -0
  142. package/source/readonly-keys-of.d.ts +38 -0
  143. package/source/readonly-tuple.d.ts +34 -0
  144. package/source/remove-prefix.d.ts +132 -0
  145. package/source/replace.d.ts +87 -0
  146. package/source/require-all-or-none.d.ts +54 -0
  147. package/source/require-at-least-one.d.ts +50 -0
  148. package/source/require-exactly-one.d.ts +48 -0
  149. package/source/require-one-or-none.d.ts +49 -0
  150. package/source/required-deep.d.ts +76 -0
  151. package/source/required-keys-of.d.ts +38 -0
  152. package/source/schema.d.ts +119 -0
  153. package/source/screaming-snake-case.d.ts +30 -0
  154. package/source/set-field-type.d.ts +67 -0
  155. package/source/set-non-nullable-deep.d.ts +85 -0
  156. package/source/set-non-nullable.d.ts +41 -0
  157. package/source/set-optional.d.ts +46 -0
  158. package/source/set-parameter-type.d.ts +125 -0
  159. package/source/set-readonly.d.ts +44 -0
  160. package/source/set-required-deep.d.ts +64 -0
  161. package/source/set-required.d.ts +79 -0
  162. package/source/set-return-type.d.ts +31 -0
  163. package/source/shared-union-fields-deep.d.ts +180 -0
  164. package/source/shared-union-fields.d.ts +79 -0
  165. package/source/simplify-deep.d.ts +117 -0
  166. package/source/simplify.d.ts +61 -0
  167. package/source/single-key-object.d.ts +28 -0
  168. package/source/snake-case.d.ts +47 -0
  169. package/source/snake-cased-properties-deep.d.ts +65 -0
  170. package/source/snake-cased-properties.d.ts +42 -0
  171. package/source/split-on-rest-element.d.ts +106 -0
  172. package/source/split.d.ts +90 -0
  173. package/source/spread.d.ts +82 -0
  174. package/source/string-repeat.d.ts +49 -0
  175. package/source/string-slice.d.ts +39 -0
  176. package/source/stringified.d.ts +25 -0
  177. package/source/structured-cloneable.d.ts +89 -0
  178. package/source/subtract.d.ts +86 -0
  179. package/source/sum.d.ts +81 -0
  180. package/source/tagged-union.d.ts +53 -0
  181. package/source/tagged.d.ts +263 -0
  182. package/source/trim.d.ts +29 -0
  183. package/source/tsconfig-json.d.ts +1324 -0
  184. package/source/tuple-of.d.ts +80 -0
  185. package/source/tuple-to-object.d.ts +47 -0
  186. package/source/tuple-to-union.d.ts +54 -0
  187. package/source/typed-array.d.ts +19 -0
  188. package/source/undefined-on-partial-deep.d.ts +83 -0
  189. package/source/union-to-intersection.d.ts +35 -0
  190. package/source/union-to-tuple.d.ts +58 -0
  191. package/source/unknown-array.d.ts +27 -0
  192. package/source/unknown-map.d.ts +26 -0
  193. package/source/unknown-record.d.ts +33 -0
  194. package/source/unknown-set.d.ts +26 -0
  195. package/source/unwrap-partial.d.ts +33 -0
  196. package/source/value-of.d.ts +24 -0
  197. package/source/words.d.ts +122 -0
  198. package/source/writable-deep.d.ts +84 -0
  199. package/source/writable-keys-of.d.ts +34 -0
  200. package/source/writable.d.ts +72 -0
  201. package/source/xor.d.ts +83 -0
@@ -0,0 +1,84 @@
1
+ import type {BuiltIns, HasMultipleCallSignatures} from './internal/index.d.ts';
2
+
3
+ /**
4
+ Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.
5
+
6
+ This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
7
+
8
+ @example
9
+ ```
10
+ import type {WritableDeep} from 'type-fest';
11
+
12
+ type Foo = {
13
+ readonly a: number;
14
+ readonly b: readonly string[]; // To show that mutability is deeply affected.
15
+ readonly c: boolean;
16
+ };
17
+
18
+ const writableDeepFoo: WritableDeep<Foo> = {a: 1, b: ['2'], c: true};
19
+ writableDeepFoo.a = 3;
20
+ writableDeepFoo.b[0] = 'new value';
21
+ writableDeepFoo.b = ['something'];
22
+ ```
23
+
24
+ Note that types containing overloaded functions are not made deeply writable due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
25
+
26
+ @see {@link Writable}
27
+ @category Object
28
+ @category Array
29
+ @category Set
30
+ @category Map
31
+ */
32
+ export type WritableDeep<T> = T extends BuiltIns
33
+ ? T
34
+ : T extends (...arguments_: any[]) => unknown
35
+ ? {} extends _WritableObjectDeep<T>
36
+ ? T
37
+ : HasMultipleCallSignatures<T> extends true
38
+ ? T
39
+ : ((...arguments_: Parameters<T>) => ReturnType<T>) & _WritableObjectDeep<T>
40
+ : T extends ReadonlyMap<unknown, unknown>
41
+ ? WritableMapDeep<T>
42
+ : T extends ReadonlySet<unknown>
43
+ ? WritableSetDeep<T>
44
+ : T extends readonly unknown[]
45
+ ? WritableArrayDeep<T>
46
+ : T extends object
47
+ ? _WritableObjectDeep<T>
48
+ : unknown;
49
+
50
+ /**
51
+ Same as `WritableDeep`, but accepts only `Map`s as inputs. Internal helper for `WritableDeep`.
52
+ */
53
+ type WritableMapDeep<MapType extends ReadonlyMap<unknown, unknown>> =
54
+ MapType extends ReadonlyMap<infer KeyType, infer ValueType>
55
+ ? Map<WritableDeep<KeyType>, WritableDeep<ValueType>>
56
+ : MapType; // Should not heppen
57
+
58
+ /**
59
+ Same as `WritableDeep`, but accepts only `Set`s as inputs. Internal helper for `WritableDeep`.
60
+ */
61
+ type WritableSetDeep<SetType extends ReadonlySet<unknown>> =
62
+ SetType extends ReadonlySet<infer ItemType>
63
+ ? Set<WritableDeep<ItemType>>
64
+ : SetType; // Should not heppen
65
+
66
+ /**
67
+ Same as `WritableDeep`, but accepts only `object`s as inputs. Internal helper for `WritableDeep`.
68
+ */
69
+ export type _WritableObjectDeep<ObjectType extends object> = {
70
+ -readonly [KeyType in keyof ObjectType]: WritableDeep<ObjectType[KeyType]>
71
+ };
72
+
73
+ /**
74
+ Same as `WritableDeep`, but accepts only `Array`s as inputs. Internal helper for `WritableDeep`.
75
+ */
76
+ type WritableArrayDeep<ArrayType extends readonly unknown[]> =
77
+ ArrayType extends readonly [] ? []
78
+ : ArrayType extends readonly [...infer U, infer V] ? [...WritableArrayDeep<U>, WritableDeep<V>]
79
+ : ArrayType extends readonly [infer U, ...infer V] ? [WritableDeep<U>, ...WritableArrayDeep<V>]
80
+ : ArrayType extends ReadonlyArray<infer U> ? Array<WritableDeep<U>>
81
+ : ArrayType extends Array<infer U> ? Array<WritableDeep<U>>
82
+ : ArrayType;
83
+
84
+ export {};
@@ -0,0 +1,34 @@
1
+ import type {ReadonlyKeysOf} from './readonly-keys-of.d.ts';
2
+
3
+ /**
4
+ Extract all writable keys from the given type.
5
+
6
+ This is useful when you want to create a new type that contains writable keys only.
7
+
8
+ @example
9
+ ```
10
+ import type {WritableKeysOf} from 'type-fest';
11
+
12
+ type User = {
13
+ name: string;
14
+ surname: string;
15
+
16
+ readonly id: number;
17
+ };
18
+
19
+ type UpdateRequest<Entity extends object> = Pick<Entity, WritableKeysOf<Entity>>;
20
+
21
+ const update1: UpdateRequest<User> = {
22
+ name: 'Alice',
23
+ surname: 'Acme',
24
+ };
25
+ ```
26
+
27
+ @category Utilities
28
+ */
29
+ export type WritableKeysOf<Type extends object> =
30
+ Type extends unknown // For distributing `Type`
31
+ ? Exclude<keyof Type, ReadonlyKeysOf<Type>>
32
+ : never; // Should never happen
33
+
34
+ export {};
@@ -0,0 +1,72 @@
1
+ import type {Except} from './except.d.ts';
2
+ import type {Simplify} from './simplify.d.ts';
3
+
4
+ /**
5
+ Create a writable version of the given array type.
6
+ */
7
+ type WritableArray<ArrayType extends readonly unknown[]> =
8
+ ArrayType extends readonly [] ? []
9
+ : ArrayType extends readonly [...infer U, infer V] ? [...U, V]
10
+ : ArrayType extends readonly [infer U, ...infer V] ? [U, ...V]
11
+ : ArrayType extends ReadonlyArray<infer U> ? U[]
12
+ : ArrayType;
13
+
14
+ /**
15
+ Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
16
+
17
+ The 2nd argument will be ignored if the input type is not an object.
18
+
19
+ Note: This type can make readonly `Set` and `Map` writable. This behavior is different from `Readonly<T>` (as of TypeScript 5.2.2). See: https://github.com/microsoft/TypeScript/issues/29655
20
+
21
+ This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
22
+
23
+ @example
24
+ ```
25
+ import type {Writable} from 'type-fest';
26
+
27
+ type Foo = {
28
+ readonly a: number;
29
+ readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
30
+ readonly c: boolean;
31
+ };
32
+
33
+ const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
34
+ writableFoo.a = 3;
35
+ // @ts-expect-error
36
+ writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
37
+ writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
38
+
39
+ type SomeWritable = Writable<Foo, 'b' | 'c'>;
40
+ // type SomeWritable = {
41
+ // readonly a: number;
42
+ // b: readonly string[]; // It's now writable. The type of the property remains unaffected.
43
+ // c: boolean; // It's now writable.
44
+ // }
45
+
46
+ // Also supports array
47
+ const readonlyArray: readonly number[] = [1, 2, 3];
48
+ // @ts-expect-error
49
+ readonlyArray.push(4); // Will fail as the array itself is readonly.
50
+ const writableArray: Writable<typeof readonlyArray> = readonlyArray as Writable<typeof readonlyArray>;
51
+ writableArray.push(4); // Will work as the array itself is now writable.
52
+ ```
53
+
54
+ @category Object
55
+ */
56
+ export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
57
+ BaseType extends ReadonlyMap<infer KeyType, infer ValueType>
58
+ ? Map<KeyType, ValueType>
59
+ : BaseType extends ReadonlySet<infer ItemType>
60
+ ? Set<ItemType>
61
+ : BaseType extends readonly unknown[]
62
+ // Handle array
63
+ ? WritableArray<BaseType>
64
+ // Handle object
65
+ : Simplify<
66
+ // Pick just the keys that are not writable from the base type.
67
+ Except<BaseType, Keys> &
68
+ // Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
69
+ {-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
70
+ >;
71
+
72
+ export {};
@@ -0,0 +1,83 @@
1
+ import type {Not} from './internal/type.d.ts';
2
+ import type {And} from './and.d.ts';
3
+ import type {Or} from './or.d.ts';
4
+
5
+ /**
6
+ Returns a boolean for whether only one of two given types is true.
7
+
8
+ Use-case: Constructing complex conditional types where one single condition must be satisfied.
9
+
10
+ @example
11
+ ```
12
+ import type {Xor} from 'type-fest';
13
+
14
+ type TT = Xor<true, true>;
15
+ //=> false
16
+
17
+ type TF = Xor<true, false>;
18
+ //=> true
19
+
20
+ type FT = Xor<false, true>;
21
+ //=> true
22
+
23
+ type FF = Xor<false, false>;
24
+ //=> false
25
+ ```
26
+
27
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
28
+ For example, `Xor<false, boolean>` expands to `Xor<false, true> | Xor<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
29
+
30
+ @example
31
+ ```
32
+ import type {Xor} from 'type-fest';
33
+
34
+ type A = Xor<false, boolean>;
35
+ //=> boolean
36
+
37
+ type B = Xor<boolean, false>;
38
+ //=> boolean
39
+
40
+ type C = Xor<true, boolean>;
41
+ //=> boolean
42
+
43
+ type D = Xor<boolean, true>;
44
+ //=> boolean
45
+
46
+ type E = Xor<boolean, boolean>;
47
+ //=> boolean
48
+ ```
49
+
50
+ Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
51
+
52
+ @example
53
+ ```
54
+ import type {Xor} from 'type-fest';
55
+
56
+ type A = Xor<true, never>;
57
+ //=> true
58
+
59
+ type B = Xor<never, true>;
60
+ //=> true
61
+
62
+ type C = Xor<false, never>;
63
+ //=> false
64
+
65
+ type D = Xor<never, false>;
66
+ //=> false
67
+
68
+ type E = Xor<boolean, never>;
69
+ //=> boolean
70
+
71
+ type F = Xor<never, boolean>;
72
+ //=> boolean
73
+
74
+ type G = Xor<never, never>;
75
+ //=> false
76
+ ```
77
+
78
+ @see {@link And}
79
+ @see {@link Or}
80
+ */
81
+ export type Xor<A extends boolean, B extends boolean> = And<Or<A, B>, Not<And<A, B>>>;
82
+
83
+ export {};