@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,98 @@
1
+ /**
2
+ Omit any index signatures from the given object type, leaving only explicitly defined properties.
3
+
4
+ This is the counterpart of `PickIndexSignature`.
5
+
6
+ Use-cases:
7
+ - Remove overly permissive signatures from third-party types.
8
+
9
+ This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
10
+
11
+ It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
12
+
13
+ (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
14
+
15
+ ```
16
+ const indexed: Record<string, unknown> = {}; // Allowed
17
+
18
+ // @ts-expect-error
19
+ const keyed: Record<'foo', unknown> = {}; // Error
20
+ // TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
21
+ ```
22
+
23
+ Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
24
+
25
+ ```
26
+ type Indexed = {} extends Record<string, unknown>
27
+ ? '✅ `{}` is assignable to `Record<string, unknown>`'
28
+ : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
29
+
30
+ type IndexedResult = Indexed;
31
+ //=> '✅ `{}` is assignable to `Record<string, unknown>`'
32
+
33
+ type Keyed = {} extends Record<'foo' | 'bar', unknown>
34
+ ? '✅ `{}` is assignable to `Record<\'foo\' | \'bar\', unknown>`'
35
+ : '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`';
36
+
37
+ type KeyedResult = Keyed;
38
+ //=> '❌ `{}` is NOT assignable to `Record<\'foo\' | \'bar\', unknown>`'
39
+ ```
40
+
41
+ Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
42
+
43
+ ```
44
+ type OmitIndexSignature<ObjectType> = {
45
+ [KeyType in keyof ObjectType // Map each key of `ObjectType`...
46
+ ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
47
+ };
48
+ ```
49
+
50
+ ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
51
+
52
+ ```
53
+ type OmitIndexSignature<ObjectType> = {
54
+ [KeyType in keyof ObjectType
55
+ // Is `{}` assignable to `Record<KeyType, unknown>`?
56
+ as {} extends Record<KeyType, unknown>
57
+ ? never // ✅ `{}` is assignable to `Record<KeyType, unknown>`
58
+ : KeyType // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
59
+ ]: ObjectType[KeyType];
60
+ };
61
+ ```
62
+
63
+ If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
64
+
65
+ @example
66
+ ```
67
+ import type {OmitIndexSignature} from 'type-fest';
68
+
69
+ type Example = {
70
+ // These index signatures will be removed.
71
+ [x: string]: any;
72
+ [x: number]: any;
73
+ [x: symbol]: any;
74
+ [x: `head-${string}`]: string;
75
+ [x: `${string}-tail`]: string;
76
+ [x: `head-${string}-tail`]: string;
77
+ [x: `${bigint}`]: string;
78
+ [x: `embedded-${number}`]: string;
79
+
80
+ // These explicitly defined keys will remain.
81
+ foo: 'bar';
82
+ qux?: 'baz';
83
+ };
84
+
85
+ type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
86
+ //=> {foo: 'bar'; qux?: 'baz'}
87
+ ```
88
+
89
+ @see {@link PickIndexSignature}
90
+ @category Object
91
+ */
92
+ export type OmitIndexSignature<ObjectType> = {
93
+ [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
94
+ ? never
95
+ : KeyType]: ObjectType[KeyType];
96
+ };
97
+
98
+ export {};
@@ -0,0 +1,3 @@
1
+ export type * from './tagged.d.ts';
2
+
3
+ export {};
@@ -0,0 +1,46 @@
1
+ import type {IsOptionalKeyOf} from './is-optional-key-of.d.ts';
2
+
3
+ /**
4
+ Extract all optional keys from the given type.
5
+
6
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
7
+
8
+ @example
9
+ ```
10
+ import type {OptionalKeysOf, Except} from 'type-fest';
11
+
12
+ type User = {
13
+ name: string;
14
+ surname: string;
15
+
16
+ luckyNumber?: number;
17
+ };
18
+
19
+ const REMOVE_FIELD = Symbol('remove field symbol');
20
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
21
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
22
+ };
23
+
24
+ const update1: UpdateOperation<User> = {
25
+ name: 'Alice',
26
+ };
27
+
28
+ const update2: UpdateOperation<User> = {
29
+ name: 'Bob',
30
+ luckyNumber: REMOVE_FIELD,
31
+ };
32
+ ```
33
+
34
+ @category Utilities
35
+ */
36
+ export type OptionalKeysOf<Type extends object> =
37
+ Type extends unknown // For distributing `Type`
38
+ ? (keyof {[Key in keyof Type as
39
+ IsOptionalKeyOf<Type, Key> extends false
40
+ ? never
41
+ : Key
42
+ ]: never
43
+ }) & keyof Type // Intersect with `keyof Type` to ensure result of `OptionalKeysOf<Type>` is always assignable to `keyof Type`
44
+ : never; // Should never happen
45
+
46
+ export {};
package/source/or.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ import type {If} from './if.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
3
+
4
+ /**
5
+ Returns a boolean for whether either of two given types is true.
6
+
7
+ Use-case: Constructing complex conditional types where at least one condition must be satisfied.
8
+
9
+ @example
10
+ ```
11
+ import type {Or} from 'type-fest';
12
+
13
+ type TT = Or<true, true>;
14
+ //=> true
15
+
16
+ type TF = Or<true, false>;
17
+ //=> true
18
+
19
+ type FT = Or<false, true>;
20
+ //=> true
21
+
22
+ type FF = Or<false, false>;
23
+ //=> false
24
+ ```
25
+
26
+ Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
27
+ For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
28
+
29
+ @example
30
+ ```
31
+ import type {Or} from 'type-fest';
32
+
33
+ type A = Or<false, boolean>;
34
+ //=> boolean
35
+
36
+ type B = Or<boolean, false>;
37
+ //=> boolean
38
+
39
+ type C = Or<true, boolean>;
40
+ //=> true
41
+
42
+ type D = Or<boolean, true>;
43
+ //=> true
44
+
45
+ type E = Or<boolean, boolean>;
46
+ //=> boolean
47
+ ```
48
+
49
+ Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
50
+
51
+ @example
52
+ ```
53
+ import type {Or} from 'type-fest';
54
+
55
+ type A = Or<true, never>;
56
+ //=> true
57
+
58
+ type B = Or<never, true>;
59
+ //=> true
60
+
61
+ type C = Or<false, never>;
62
+ //=> false
63
+
64
+ type D = Or<never, false>;
65
+ //=> false
66
+
67
+ type E = Or<boolean, never>;
68
+ //=> boolean
69
+
70
+ type F = Or<never, boolean>;
71
+ //=> boolean
72
+
73
+ type G = Or<never, never>;
74
+ //=> false
75
+ ```
76
+
77
+ @see {@link And}
78
+ @see {@link Xor}
79
+ */
80
+ export type Or<A extends boolean, B extends boolean> =
81
+ _Or<If<IsNever<A>, false, A>, If<IsNever<B>, false, B>>; // `never` is treated as `false`
82
+
83
+ export type _Or<A extends boolean, B extends boolean> = A extends true
84
+ ? true
85
+ : B extends true
86
+ ? true
87
+ : false;
88
+
89
+ export {};
@@ -0,0 +1,43 @@
1
+ import type {Merge} from './merge.d.ts';
2
+
3
+ /**
4
+ Override existing properties of the given type. Similar to `Merge`, but enforces that the original type has the properties you want to override.
5
+
6
+ This is useful when you want to override existing properties with a different type and make sure that these properties really exist in the original.
7
+
8
+ @example
9
+ ```
10
+ import type {OverrideProperties} from 'type-fest';
11
+
12
+ type Foo = {
13
+ a: string;
14
+ b: string;
15
+ };
16
+
17
+ type Bar = OverrideProperties<Foo, {b: number}>;
18
+ //=> {a: string; b: number}
19
+
20
+ // @ts-expect-error
21
+ type Baz = OverrideProperties<Foo, {c: number}>;
22
+ // Error, type '{ c: number; }' does not satisfy the constraint '{ c: never; }'
23
+
24
+ // @ts-expect-error
25
+ type Fizz = OverrideProperties<Foo, {b: number; c: number}>;
26
+ // Error, type '{ b: number; c: number; }' does not satisfy the constraint '{ b: number; c: never; }'
27
+ ```
28
+
29
+ @category Object
30
+ */
31
+ export type OverrideProperties<
32
+ TOriginal,
33
+ // This first bit where we use `Partial` is to enable autocomplete
34
+ // and the second bit with the mapped type is what enforces that we don't try
35
+ // to override properties that doesn't exist in the original type.
36
+ TOverride extends Partial<Record<keyof TOriginal, unknown>> & {
37
+ [Key in keyof TOverride]: Key extends keyof TOriginal
38
+ ? TOverride[Key]
39
+ : never;
40
+ },
41
+ > = Merge<TOriginal, TOverride>;
42
+
43
+ export {};