type-plus 7.3.0 → 7.4.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 (248) hide show
  1. package/README.md +131 -156
  2. package/cjs/any/any_type.d.ts +8 -8
  3. package/cjs/any/any_type.d.ts.map +1 -1
  4. package/cjs/array/array.at.d.ts +3 -1
  5. package/cjs/array/array.at.d.ts.map +1 -1
  6. package/cjs/array/array.find.d.ts +3 -1
  7. package/cjs/array/array.find.d.ts.map +1 -1
  8. package/cjs/array/array.find_last.d.ts +3 -1
  9. package/cjs/array/array.find_last.d.ts.map +1 -1
  10. package/cjs/array/array.some.d.ts +1 -1
  11. package/cjs/array/array.some.d.ts.map +1 -1
  12. package/cjs/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
  13. package/cjs/array/array_plus.concat.d.ts.map +1 -0
  14. package/cjs/array/{array.concat.js → array_plus.concat.js} +1 -1
  15. package/cjs/array/array_plus.concat.js.map +1 -0
  16. package/cjs/array/array_plus.d.ts +3 -2
  17. package/cjs/array/array_plus.d.ts.map +1 -1
  18. package/cjs/array/array_plus.filter.d.ts +2 -0
  19. package/cjs/array/array_plus.filter.d.ts.map +1 -0
  20. package/cjs/array/array_plus.filter.js +3 -0
  21. package/cjs/array/array_plus.filter.js.map +1 -0
  22. package/cjs/array/array_plus.pad_start.d.ts +5 -0
  23. package/cjs/array/array_plus.pad_start.d.ts.map +1 -0
  24. package/cjs/array/array_plus.pad_start.js +3 -0
  25. package/cjs/array/array_plus.pad_start.js.map +1 -0
  26. package/cjs/array/array_type.d.ts +30 -12
  27. package/cjs/array/array_type.d.ts.map +1 -1
  28. package/cjs/array/filter.d.ts +24 -4
  29. package/cjs/array/filter.d.ts.map +1 -1
  30. package/cjs/array/head.d.ts +18 -1
  31. package/cjs/array/head.d.ts.map +1 -1
  32. package/cjs/array/intersect_of_props.d.ts +5 -3
  33. package/cjs/array/intersect_of_props.d.ts.map +1 -1
  34. package/cjs/array/last.d.ts +16 -2
  35. package/cjs/array/last.d.ts.map +1 -1
  36. package/cjs/array/literal_array.d.ts +5 -0
  37. package/cjs/array/literal_array.d.ts.map +1 -1
  38. package/cjs/array/literal_array.js +5 -0
  39. package/cjs/array/literal_array.js.map +1 -1
  40. package/cjs/array/pad_start.d.ts +5 -5
  41. package/cjs/array/pad_start.d.ts.map +1 -1
  42. package/cjs/array/reduce_while.d.ts +6 -0
  43. package/cjs/array/reduce_while.d.ts.map +1 -1
  44. package/cjs/array/reduce_while.js +6 -0
  45. package/cjs/array/reduce_while.js.map +1 -1
  46. package/cjs/array/reverse.d.ts +5 -0
  47. package/cjs/array/reverse.d.ts.map +1 -1
  48. package/cjs/array/union_of_props.d.ts +1 -1
  49. package/cjs/array/union_of_props.d.ts.map +1 -1
  50. package/cjs/functional/compose.d.ts +2 -1
  51. package/cjs/functional/compose.d.ts.map +1 -1
  52. package/cjs/functional/compose.js.map +1 -1
  53. package/cjs/functional/context.d.ts.map +1 -1
  54. package/cjs/index.d.ts +19 -3
  55. package/cjs/index.d.ts.map +1 -1
  56. package/cjs/index.js +9 -3
  57. package/cjs/index.js.map +1 -1
  58. package/cjs/math/numeric_struct.d.ts +1 -1
  59. package/cjs/math/numeric_struct.d.ts.map +1 -1
  60. package/cjs/mix_types/any_or_never_type.d.ts +18 -10
  61. package/cjs/mix_types/any_or_never_type.d.ts.map +1 -1
  62. package/cjs/nodejs/isNodeError.d.ts.map +1 -1
  63. package/cjs/nominal/brand.d.ts.map +1 -1
  64. package/cjs/nominal/flavor.d.ts.map +1 -1
  65. package/cjs/testing/test_type.d.ts +44 -1
  66. package/cjs/testing/test_type.d.ts.map +1 -1
  67. package/cjs/tuple/common_prop_keys.d.ts +29 -0
  68. package/cjs/tuple/common_prop_keys.d.ts.map +1 -0
  69. package/cjs/tuple/common_prop_keys.js.map +1 -0
  70. package/cjs/tuple/create_tuple.d.ts.map +1 -1
  71. package/cjs/tuple/drop.d.ts +72 -0
  72. package/cjs/tuple/drop.d.ts.map +1 -0
  73. package/cjs/{array → tuple}/drop.js +3 -1
  74. package/cjs/tuple/drop.js.map +1 -0
  75. package/{esm/array → cjs/tuple}/tail.d.ts +1 -1
  76. package/cjs/{array → tuple}/tail.d.ts.map +1 -1
  77. package/cjs/{array → tuple}/tail.js.map +1 -1
  78. package/cjs/tuple/tuple_plus.d.ts +2 -1
  79. package/cjs/tuple/tuple_plus.d.ts.map +1 -1
  80. package/cjs/tuple/tuple_plus.filter.d.ts +13 -0
  81. package/cjs/tuple/tuple_plus.filter.d.ts.map +1 -0
  82. package/cjs/tuple/tuple_plus.filter.js +3 -0
  83. package/cjs/tuple/tuple_plus.filter.js.map +1 -0
  84. package/cjs/tuple/tuple_plus.js +0 -15
  85. package/cjs/tuple/tuple_plus.js.map +1 -1
  86. package/cjs/tuple/tuple_plus.pad_start.d.ts +8 -3
  87. package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  88. package/esm/any/any_type.d.ts +8 -8
  89. package/esm/any/any_type.d.ts.map +1 -1
  90. package/esm/array/array.at.d.ts +3 -1
  91. package/esm/array/array.at.d.ts.map +1 -1
  92. package/esm/array/array.find.d.ts +3 -1
  93. package/esm/array/array.find.d.ts.map +1 -1
  94. package/esm/array/array.find_last.d.ts +3 -1
  95. package/esm/array/array.find_last.d.ts.map +1 -1
  96. package/esm/array/array.some.d.ts +1 -1
  97. package/esm/array/array.some.d.ts.map +1 -1
  98. package/esm/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
  99. package/esm/array/array_plus.concat.d.ts.map +1 -0
  100. package/esm/array/array_plus.concat.js +2 -0
  101. package/esm/array/array_plus.concat.js.map +1 -0
  102. package/esm/array/array_plus.d.ts +3 -2
  103. package/esm/array/array_plus.d.ts.map +1 -1
  104. package/esm/array/array_plus.filter.d.ts +2 -0
  105. package/esm/array/array_plus.filter.d.ts.map +1 -0
  106. package/esm/array/array_plus.filter.js +2 -0
  107. package/esm/array/array_plus.filter.js.map +1 -0
  108. package/esm/array/array_plus.pad_start.d.ts +5 -0
  109. package/esm/array/array_plus.pad_start.d.ts.map +1 -0
  110. package/esm/array/array_plus.pad_start.js +2 -0
  111. package/esm/array/array_plus.pad_start.js.map +1 -0
  112. package/esm/array/array_type.d.ts +30 -12
  113. package/esm/array/array_type.d.ts.map +1 -1
  114. package/esm/array/filter.d.ts +24 -4
  115. package/esm/array/filter.d.ts.map +1 -1
  116. package/esm/array/head.d.ts +18 -1
  117. package/esm/array/head.d.ts.map +1 -1
  118. package/esm/array/intersect_of_props.d.ts +5 -3
  119. package/esm/array/intersect_of_props.d.ts.map +1 -1
  120. package/esm/array/last.d.ts +16 -2
  121. package/esm/array/last.d.ts.map +1 -1
  122. package/esm/array/literal_array.d.ts +5 -0
  123. package/esm/array/literal_array.d.ts.map +1 -1
  124. package/esm/array/literal_array.js +5 -0
  125. package/esm/array/literal_array.js.map +1 -1
  126. package/esm/array/pad_start.d.ts +5 -5
  127. package/esm/array/pad_start.d.ts.map +1 -1
  128. package/esm/array/reduce_while.d.ts +6 -0
  129. package/esm/array/reduce_while.d.ts.map +1 -1
  130. package/esm/array/reduce_while.js +6 -0
  131. package/esm/array/reduce_while.js.map +1 -1
  132. package/esm/array/reverse.d.ts +5 -0
  133. package/esm/array/reverse.d.ts.map +1 -1
  134. package/esm/array/union_of_props.d.ts +1 -1
  135. package/esm/array/union_of_props.d.ts.map +1 -1
  136. package/esm/functional/compose.d.ts +2 -1
  137. package/esm/functional/compose.d.ts.map +1 -1
  138. package/esm/functional/compose.js.map +1 -1
  139. package/esm/functional/context.d.ts.map +1 -1
  140. package/esm/index.d.ts +19 -3
  141. package/esm/index.d.ts.map +1 -1
  142. package/esm/index.js +4 -2
  143. package/esm/index.js.map +1 -1
  144. package/esm/math/numeric_struct.d.ts +1 -1
  145. package/esm/math/numeric_struct.d.ts.map +1 -1
  146. package/esm/mix_types/any_or_never_type.d.ts +18 -10
  147. package/esm/mix_types/any_or_never_type.d.ts.map +1 -1
  148. package/esm/nodejs/isNodeError.d.ts.map +1 -1
  149. package/esm/nominal/brand.d.ts.map +1 -1
  150. package/esm/nominal/flavor.d.ts.map +1 -1
  151. package/esm/testing/test_type.d.ts +44 -1
  152. package/esm/testing/test_type.d.ts.map +1 -1
  153. package/esm/tuple/common_prop_keys.d.ts +29 -0
  154. package/esm/tuple/common_prop_keys.d.ts.map +1 -0
  155. package/esm/tuple/common_prop_keys.js.map +1 -0
  156. package/esm/tuple/create_tuple.d.ts.map +1 -1
  157. package/esm/tuple/drop.d.ts +72 -0
  158. package/esm/tuple/drop.d.ts.map +1 -0
  159. package/esm/tuple/drop.js +9 -0
  160. package/esm/tuple/drop.js.map +1 -0
  161. package/{cjs/array → esm/tuple}/tail.d.ts +1 -1
  162. package/esm/{array → tuple}/tail.d.ts.map +1 -1
  163. package/esm/{array → tuple}/tail.js.map +1 -1
  164. package/esm/tuple/tuple_plus.d.ts +2 -1
  165. package/esm/tuple/tuple_plus.d.ts.map +1 -1
  166. package/esm/tuple/tuple_plus.filter.d.ts +13 -0
  167. package/esm/tuple/tuple_plus.filter.d.ts.map +1 -0
  168. package/esm/tuple/tuple_plus.filter.js +2 -0
  169. package/esm/tuple/tuple_plus.filter.js.map +1 -0
  170. package/esm/tuple/tuple_plus.js +1 -1
  171. package/esm/tuple/tuple_plus.js.map +1 -1
  172. package/esm/tuple/tuple_plus.pad_start.d.ts +8 -3
  173. package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  174. package/package.json +15 -11
  175. package/ts/any/any_type.ts +8 -9
  176. package/ts/any/readme.md +91 -7
  177. package/ts/array/array.at.ts +3 -1
  178. package/ts/array/array.find.ts +3 -1
  179. package/ts/array/array.find_last.ts +3 -1
  180. package/ts/array/array.some.ts +1 -1
  181. package/ts/array/{array.concat.ts → array_plus.concat.ts} +3 -0
  182. package/ts/array/array_plus.filter.ts +5 -0
  183. package/ts/array/array_plus.pad_start.ts +13 -0
  184. package/ts/array/array_plus.ts +3 -2
  185. package/ts/array/array_type.ts +30 -12
  186. package/ts/array/filter.ts +27 -22
  187. package/ts/array/head.ts +18 -1
  188. package/ts/array/intersect_of_props.ts +7 -3
  189. package/ts/array/last.ts +16 -2
  190. package/ts/array/literal_array.ts +5 -0
  191. package/ts/array/pad_start.ts +6 -10
  192. package/ts/array/readme.md +181 -16
  193. package/ts/array/reduce_while.ts +6 -0
  194. package/ts/array/reverse.ts +5 -0
  195. package/ts/array/union_of_props.ts +1 -1
  196. package/ts/assertion/readme.md +3 -3
  197. package/ts/functional/compose.ts +2 -1
  198. package/ts/functional/context.ts +1 -1
  199. package/ts/index.ts +22 -3
  200. package/ts/math/numeric_struct.ts +9 -9
  201. package/ts/mix_types/any_or_never_type.ts +18 -10
  202. package/ts/mix_types/readme.md +40 -0
  203. package/ts/nodejs/isNodeError.ts +13 -13
  204. package/ts/nominal/brand.ts +1 -1
  205. package/ts/nominal/flavor.ts +1 -1
  206. package/ts/testing/readme.md +30 -0
  207. package/ts/testing/test_type.ts +90 -47
  208. package/ts/tuple/common_prop_keys.ts +55 -0
  209. package/ts/tuple/create_tuple.ts +9 -9
  210. package/ts/tuple/drop.ts +124 -0
  211. package/ts/tuple/readme.md +116 -1
  212. package/ts/{array → tuple}/tail.ts +1 -1
  213. package/ts/tuple/tuple_plus.filter.ts +29 -0
  214. package/ts/tuple/tuple_plus.pad_start.ts +26 -13
  215. package/ts/tuple/tuple_plus.ts +2 -1
  216. package/cjs/array/array.concat.d.ts.map +0 -1
  217. package/cjs/array/array.concat.js.map +0 -1
  218. package/cjs/array/common_prop_keys.d.ts +0 -11
  219. package/cjs/array/common_prop_keys.d.ts.map +0 -1
  220. package/cjs/array/common_prop_keys.js.map +0 -1
  221. package/cjs/array/drop.d.ts +0 -19
  222. package/cjs/array/drop.d.ts.map +0 -1
  223. package/cjs/array/drop.js.map +0 -1
  224. package/cjs/array/index.d.ts +0 -17
  225. package/cjs/array/index.d.ts.map +0 -1
  226. package/cjs/array/index.js +0 -33
  227. package/cjs/array/index.js.map +0 -1
  228. package/esm/array/array.concat.d.ts.map +0 -1
  229. package/esm/array/array.concat.js +0 -2
  230. package/esm/array/array.concat.js.map +0 -1
  231. package/esm/array/common_prop_keys.d.ts +0 -11
  232. package/esm/array/common_prop_keys.d.ts.map +0 -1
  233. package/esm/array/common_prop_keys.js.map +0 -1
  234. package/esm/array/drop.d.ts +0 -19
  235. package/esm/array/drop.d.ts.map +0 -1
  236. package/esm/array/drop.js +0 -7
  237. package/esm/array/drop.js.map +0 -1
  238. package/esm/array/index.d.ts +0 -17
  239. package/esm/array/index.d.ts.map +0 -1
  240. package/esm/array/index.js +0 -17
  241. package/esm/array/index.js.map +0 -1
  242. package/ts/array/common_prop_keys.ts +0 -18
  243. package/ts/array/drop.ts +0 -71
  244. package/ts/array/index.ts +0 -16
  245. /package/cjs/{array → tuple}/common_prop_keys.js +0 -0
  246. /package/cjs/{array → tuple}/tail.js +0 -0
  247. /package/esm/{array → tuple}/common_prop_keys.js +0 -0
  248. /package/esm/{array → tuple}/tail.js +0 -0
@@ -1,3 +1,8 @@
1
+ /**
2
+ * ⚗️ *transform*
3
+ *
4
+ * reverses the order of `A`.
5
+ */
1
6
  export type Reverse<A extends unknown[]> = number extends A['length']
2
7
  ? A
3
8
  : A['length'] extends 0
@@ -1,5 +1,5 @@
1
1
  import type { KeyTypes } from '../object/index.js'
2
- import type { Tail } from './tail.js'
2
+ import type { Tail } from '../tuple/tail.js'
3
3
 
4
4
  /**
5
5
  * Gets the union of properties of the elements in `A`
@@ -9,11 +9,11 @@ They throw an error if the condition is not met, and return nothing otherwise.
9
9
  These assertion functions are typically used in runtime,
10
10
  so that that type of the value can be narrowed down.
11
11
 
12
- ## assertType
12
+ ## [assertType](./assert_type.ts)
13
13
 
14
- `assertType<T>(subject)`:
14
+ `assertType<T>(subject)`
15
15
 
16
- ✔️ `immediate`
16
+ 💥 `immediate`
17
17
 
18
18
  It ensures `subject` satisfies `T`.
19
19
  It is similar to `const x: T = subject` without introducing an unused variable.
@@ -1,4 +1,5 @@
1
- import type { Head, Last } from '../array/index.js'
1
+ import type { Head } from '../array/head.js'
2
+ import type { Last } from '../array/last.js'
2
3
  import type { AnyFunction } from '../function/any_function.js'
3
4
 
4
5
  /**
@@ -27,7 +27,7 @@ export type ContextBuilder<Init extends ContextBaseShape, Ctx extends ContextBas
27
27
  */
28
28
  extend<Additional extends ContextBaseShape = ContextBaseShape>(
29
29
  extender: ContextExtender<Ctx, Additional>
30
- ): ContextBuilder<Init, LeftJoin<Ctx, Additional>>
30
+ ): ContextBuilder<Init, LeftJoin<Ctx, Additional>>,
31
31
  /**
32
32
  * Build and return the context.
33
33
  */
package/ts/index.ts CHANGED
@@ -1,10 +1,22 @@
1
1
  export type { AnyType, IsAny, IsNotAny, NotAnyType } from './any/any_type.js'
2
2
  export type { At } from './array/array.at.js'
3
- export type { Concat } from './array/array.concat.js'
3
+ export type { FindFirst } from './array/array.find.js'
4
+ export type { FindLast } from './array/array.find_last.js'
5
+ export type { Some } from './array/array.some.js'
6
+ export type { Concat } from './array/array_plus.concat.js'
4
7
  export * as ArrayPlus from './array/array_plus.js'
5
8
  export type { ArrayType, IsArray, IsNotArray, NotArrayType } from './array/array_type.js'
6
- export * from './array/index.js'
7
- export * from './assertion/assert_type.js'
9
+ export type { Filter, KeepMatch } from './array/filter.js'
10
+ export type { Head } from './array/head.js'
11
+ export type { IntersectOfProps, MapToProp } from './array/intersect_of_props.js'
12
+ export type { Last } from './array/last.js'
13
+ export { literalArray } from './array/literal_array.js'
14
+ export type { PadStart } from './array/pad_start.js'
15
+ export { reduceWhile } from './array/reduce_while.js'
16
+ export type { Reverse } from './array/reverse.js'
17
+ export type { PropUnion, UnionOfProps } from './array/union_of_props.js'
18
+ export type { UnionOfValues } from './array/union_of_values.js'
19
+ export { assertType } from './assertion/assert_type.js'
8
20
  export type { BigintType, IsBigint, IsNotBigint, NotBigintType } from './bigint/bigint_type.js'
9
21
  export type { StringToBigint } from './bigint/cast.js'
10
22
  export type {
@@ -82,7 +94,11 @@ export type { IsNotString, IsString, NotStringType, StringType } from './string/
82
94
  export type { IsNotSymbol, IsSymbol, NotSymbolType, SymbolType } from './symbol/symbol_type.js'
83
95
  export * from './testing/stub.js'
84
96
  export * from './testing/test_type.js'
97
+ export type { CommonPropKeys } from './tuple/common_prop_keys.js'
85
98
  export * from './tuple/create_tuple.js'
99
+ export { drop } from './tuple/drop.js'
100
+ export type { DropFirst, DropLast, DropMatch, DropNull, DropNullable, DropUndefined } from './tuple/drop.js'
101
+ export type { Tail } from './tuple/tail.js'
86
102
  export * as TuplePlus from './tuple/tuple_plus.js'
87
103
  export type { IsNotTuple, IsTuple, NotTupleType, TupleType } from './tuple/tuple_type.js'
88
104
  export * from './type-guard/is_type.js'
@@ -100,3 +116,6 @@ export * from './unpartial.js'
100
116
  export * from './utils/index.js'
101
117
  export type { IsNotVoid, IsVoid, NotVoidType, VoidType } from './void/void_type.js'
102
118
 
119
+
120
+
121
+
@@ -1,4 +1,4 @@
1
- import type { Tail } from '../array/tail.js'
1
+ import type { Tail } from '../tuple/tail.js'
2
2
  import type { PadStart } from '../tuple/tuple_plus.pad_start.js'
3
3
  import type { Add as NumericAdd } from './add.js'
4
4
  import type { ToNegative } from './math_plus.to_negative.js'
@@ -631,14 +631,14 @@ export namespace Digit {
631
631
  ][A][B]
632
632
 
633
633
  export type Plus10 = { [k in number]: number } & {
634
- '-1': 9
635
- '-2': 8
636
- '-3': 7
637
- '-4': 6
638
- '-5': 5
639
- '-6': 4
640
- '-7': 3
641
- '-8': 2
634
+ '-1': 9,
635
+ '-2': 8,
636
+ '-3': 7,
637
+ '-4': 6,
638
+ '-5': 5,
639
+ '-6': 4,
640
+ '-7': 3,
641
+ '-8': 2,
642
642
  '-9': 1
643
643
  }
644
644
  export type Multiply<A extends number, B extends number> = [
@@ -1,22 +1,30 @@
1
- import type { IsNever } from '../never/never_type.js'
2
- import type { IsAny } from '../any/any_type.js'
1
+ import type { AnyType } from '../any/any_type.js'
2
+ import type { NeverType } from '../never/never_type.js'
3
3
 
4
4
  /**
5
- * 🐾 Parse `T` to ensure it is either exactly `any` or exactly `never`.
5
+ * Parse `T` to ensure it is either exactly `any` or exactly `never`.
6
+ *
7
+ * 🌪️ *filter*
8
+ * 🩳 *shortcut*
6
9
  *
7
10
  * @example
8
11
  * ```ts
9
- * type R = AnyType<any> // any
12
+ * type R = AnyOrNeverType<any> // any
13
+ * type R = AnyOrNeverType<never> // never
14
+ * type R = AnyOrNeverType<never, 1, 2> // 1
10
15
  *
11
- * type R = AnyType<never> // never
12
- * type R = AnyType<unknown> // never
13
- * type R = AnyType<string | boolean> // never
16
+ * type R = AnyOrNeverType<unknown> // never
17
+ * type R = AnyOrNeverType<unknown, 1, 2> // 2
18
+ * type R = AnyOrNeverType<string | boolean> // never
14
19
  * ```
15
20
  */
16
- export type AnyOrNeverType<T, Then = T, Else = never> = IsNever<T, Then, IsAny<T, Then, Else>>
21
+ export type AnyOrNeverType<T, Then = T, Else = never> = NeverType<T, Then, AnyType<T, Then, Else>>
17
22
 
18
23
  /**
19
- * 🎭 Validate if `T` is either exactly `any` or exactly `never`.
24
+ * Validate if `T` is either exactly `any` or exactly `never`.
25
+ *
26
+ * 🎭 *validate*
27
+ * 🩳 *shortcut*
20
28
  *
21
29
  * @example
22
30
  * ```ts
@@ -27,4 +35,4 @@ export type AnyOrNeverType<T, Then = T, Else = never> = IsNever<T, Then, IsAny<T
27
35
  * type R = IsAnyOrNever<unknown> // false
28
36
  * ```
29
37
  */
30
- export type IsAnyOrNever<T, Then = true, Else = false> = IsNever<T, Then, IsAny<T, Then, Else>>
38
+ export type IsAnyOrNever<T, Then = true, Else = false> = NeverType<T, Then, AnyType<T, Then, Else>>
@@ -0,0 +1,40 @@
1
+ # Mix Types
2
+
3
+ This folder contains types and utilities that work across multiple types.
4
+
5
+ ## [AnyOrNeverType](./any_or_never_type.ts)
6
+
7
+ `AnyOrNeverType<T, Then = T, Else = never>` 🎭 🩳
8
+
9
+ Filter `T` to ensure it is either exactly `any` or exactly `never`.
10
+
11
+ 🌪️ *filter*
12
+ 🩳 *shortcut*
13
+
14
+ ```ts
15
+ import type { AnyOrNeverType } from 'type-plus'
16
+
17
+ type R = AnyOrNeverType<any> // any
18
+ type R = AnyOrNeverType<never> // never
19
+ type R = AnyOrNeverType<never, 1, 2> // 1
20
+
21
+ type R = AnyOrNeverType<unknown, 1, 2> // 2
22
+ ```
23
+
24
+ ## [IsAnyOrNever](./any_or_never_type.ts)
25
+
26
+ `IsAnyOrNever<T, Then = true, Else = false>` 🎭 🩳
27
+
28
+ Validate if `T` is either exactly `any` or exactly `never`.
29
+
30
+ 🎭 *validate*
31
+ 🩳 *shortcut*
32
+
33
+ ```ts
34
+ import type { IsAnyOrNever } from 'type-plus'
35
+
36
+ type R = IsAnyOrNever<any> // true
37
+ type R = IsAnyOrNever<never> // true
38
+
39
+ type R = IsAnyOrNever<unknown> // false
40
+ ```
@@ -1,17 +1,17 @@
1
1
  export type SystemErrors = {
2
- EACCES: Error & { code: 'EACCES' }
3
- EADDRINUSE: Error & { code: 'EADDRINUSE' }
4
- ECONNREFUSED: Error
5
- ECONNRESET: Error
6
- EEXIST: Error
7
- EISDIR: Error
8
- EMFILE: Error
9
- ENOENT: Error & { code: 'ENOENT'; path: string }
10
- ENOTDIR: Error
11
- ENOTEMPTY: Error
12
- ENOTFOUND: Error
13
- EPERM: Error
14
- EPIPE: Error
2
+ EACCES: Error & { code: 'EACCES' },
3
+ EADDRINUSE: Error & { code: 'EADDRINUSE' },
4
+ ECONNREFUSED: Error,
5
+ ECONNRESET: Error,
6
+ EEXIST: Error,
7
+ EISDIR: Error,
8
+ EMFILE: Error,
9
+ ENOENT: Error & { code: 'ENOENT', path: string },
10
+ ENOTDIR: Error,
11
+ ENOTEMPTY: Error,
12
+ ENOTFOUND: Error,
13
+ EPERM: Error,
14
+ EPIPE: Error,
15
15
  ETIMEDOUT: Error
16
16
  }
17
17
 
@@ -17,7 +17,7 @@ export type Brand<B extends string, T = never> = [T] extends [null] | [undefined
17
17
  * A branded type of `B` with value of `T`.
18
18
  */
19
19
  export interface Branded<B extends string, T> {
20
- [typeSym]: B
20
+ [typeSym]: B,
21
21
  [valueSym]: T
22
22
  }
23
23
 
@@ -26,7 +26,7 @@ export interface Flavored<F extends string> {
26
26
  * A special flavored type for special types.
27
27
  */
28
28
  export interface FlavoredUnit<F extends string, T> {
29
- [typeSym]?: F
29
+ [typeSym]?: F,
30
30
  [valueSym]: T
31
31
  }
32
32
 
@@ -16,4 +16,34 @@ import { testType } from 'type-plus'
16
16
  testType.any<T>(true) // T is `any`
17
17
  testType.equal<A, B>(true) // A is equal to B
18
18
  testType.never<T>(false) // T is not `never`
19
+
20
+ const t = testType.equal<SomeComplexType, SomeCompositeType>(true)
21
+ type T = typeof t // type resolution
22
+ ```
23
+
24
+ ## [testType.inspect](./test_type.ts)
25
+
26
+ `testType.inspect<T>(fn)`
27
+
28
+ A quick way to inspect a type.
29
+
30
+ ```ts
31
+ import { testType } from 'type-plus'
32
+
33
+ testType.inspect<SomeType>(t => {
34
+ type T = typeof t.type // type resolution
35
+ })
36
+ ```
37
+
38
+ It also provides additional methods and predefined inspections so that you can quickly check how the type behaves in specific cases.
39
+
40
+ ```ts
41
+ import { testType } from 'type-plus'
42
+
43
+ testType.inspect<SomeType>(t => {
44
+ t.extends<AnotherType>() // true or false
45
+ t.union<number>() // SomeType | number`
46
+ t.intersect<string>() // `SomeType & string`
47
+ t.extends_boolean // true or false
48
+ })
19
49
  ```
@@ -29,13 +29,13 @@ interface TestType {
29
29
  *
30
30
  * @return `expected` as `A` for type inspection.
31
31
  */
32
- equal<A, B, C>(expected: IsEqual<A, B> & IsEqual<A, C>): A
32
+ equal<A, B, C>(expected: IsEqual<A, B> & IsEqual<A, C>): A,
33
33
  /**
34
34
  * Check if type `A` is equal to type `B`.
35
35
  *
36
36
  * @return `expected` as `A` for type inspection.
37
37
  */
38
- equal<A, B>(expected: IsEqual<A, B>): A
38
+ equal<A, B>(expected: IsEqual<A, B>): A,
39
39
  /**
40
40
  * Check if `A` can assign to `B`.
41
41
  *
@@ -57,7 +57,7 @@ interface TestType {
57
57
  *
58
58
  * @return `expected` as `A` for type inspection.
59
59
  */
60
- canAssign<A, B>(expected: CanAssign<A, B>): A
60
+ canAssign<A, B>(expected: CanAssign<A, B>): A,
61
61
  /**
62
62
  * Check if `A` can fully assign to `B`.
63
63
  *
@@ -72,91 +72,91 @@ interface TestType {
72
72
  *
73
73
  * @return `expected` as `A` for type inspection.
74
74
  */
75
- strictCanAssign<A, B>(expected: StrictCanAssign<A, B>): A
75
+ strictCanAssign<A, B>(expected: StrictCanAssign<A, B>): A,
76
76
  /**
77
77
  * Check if type `T` is exactly `any`.
78
78
  *
79
79
  * @return `expected` as `T` for type inspection.
80
80
  */
81
- any<T>(expected: IsAny<T>): T
81
+ any<T>(expected: IsAny<T>): T,
82
82
  /**
83
83
  * Check if type `T` is exactly `array`.
84
84
  *
85
85
  * @return `expected` as `T` for type inspection.
86
86
  */
87
- array<T>(expected: IsArray<T>): T
87
+ array<T>(expected: IsArray<T>): T,
88
88
  /**
89
89
  * Check if type `T` is exactly `bigint`.
90
90
  *
91
91
  * @return `expected` as `T` for type inspection.
92
92
  */
93
- strictBigint<T>(expected: IsStrictBigint<T>): T
93
+ strictBigint<T>(expected: IsStrictBigint<T>): T,
94
94
  /**
95
95
  * Check if type `T` is `bigint` or bigint literals.
96
96
  *
97
97
  * @return `expected` as `T` for type inspection.
98
98
  */
99
- bigint<T>(expected: IsBigint<T>): T
99
+ bigint<T>(expected: IsBigint<T>): T,
100
100
  /**
101
101
  * Check if type `T` is exactly `boolean`.
102
102
  *
103
103
  * @return `expected` as `T` for type inspection.
104
104
  */
105
- strictBoolean<T>(expected: IsStrictBoolean<T>): T
105
+ strictBoolean<T>(expected: IsStrictBoolean<T>): T,
106
106
  /**
107
107
  * Check if type `T` is `boolean` and boolean literals.
108
108
  *
109
109
  * @return `expected` as `T` for type inspection.
110
110
  */
111
- boolean<T>(expected: IsBoolean<T>): T
111
+ boolean<T>(expected: IsBoolean<T>): T,
112
112
  /**
113
113
  * Check if type `T` is exactly `true`.
114
114
  *
115
115
  * @return `expected` as `T` for type inspection.
116
116
  */
117
- true<T>(expected: IsTrue<T>): T
117
+ true<T>(expected: IsTrue<T>): T,
118
118
  /**
119
119
  * Check if type `T` is exactly `false`.
120
120
  *
121
121
  * @return `expected` as `T` for type inspection.
122
122
  */
123
- false<T>(expected: IsFalse<T>): T
123
+ false<T>(expected: IsFalse<T>): T,
124
124
  /**
125
125
  * Check if type `T` is exactly `boolean`.
126
126
  *
127
127
  * @return `expected` as `T` for type inspection.
128
128
  */
129
- strictFunction<T>(expected: IsStrictFunction<T>): T
129
+ strictFunction<T>(expected: IsStrictFunction<T>): T,
130
130
  /**
131
131
  * Check if type `T` is `boolean` and boolean literals.
132
132
  *
133
133
  * @return `expected` as `T` for type inspection.
134
134
  */
135
- function<T>(expected: IsFunction<T>): T
135
+ function<T>(expected: IsFunction<T>): T,
136
136
  /**
137
137
  * Check if type `T` is exactly `never`.
138
138
  *
139
139
  * @return `expected` as `T` for type inspection.
140
140
  */
141
- never<T>(expected: IsNever<T>): T
141
+ never<T>(expected: IsNever<T>): T,
142
142
  /**
143
143
  * Check if type `T` is exactly `null`.
144
144
  *
145
145
  * @return `expected` as `T` for type inspection.
146
146
  */
147
- null<T>(expected: IsNull<T>): T
147
+ null<T>(expected: IsNull<T>): T,
148
148
  /**
149
149
  * Check if type `T` is exactly `number`.
150
150
  *
151
151
  * @return `expected` as `T` for type inspection.
152
152
  */
153
- strictNumber<T>(expected: IsStrictNumber<T>): T
153
+ strictNumber<T>(expected: IsStrictNumber<T>): T,
154
154
  /**
155
155
  * Check if type `T` is `number` or number literals.
156
156
  *
157
157
  * @return `expected` as `T` for type inspection.
158
158
  */
159
- number<T>(expected: IsNumber<T>): T
159
+ number<T>(expected: IsNumber<T>): T,
160
160
  /**
161
161
  * Check if type `T` is `object`.
162
162
  *
@@ -164,50 +164,50 @@ interface TestType {
164
164
  *
165
165
  * @return `expected` as `T` for type inspection.
166
166
  */
167
- object<T>(expected: IsObject<T>): T
167
+ object<T>(expected: IsObject<T>): T,
168
168
  /**
169
169
  * Check if type `T` is exactly `string`.
170
170
  *
171
171
  * @return `expected` as `T` for type inspection.
172
172
  */
173
- strictString<T>(expected: IsStrictString<T>): T
173
+ strictString<T>(expected: IsStrictString<T>): T,
174
174
  /**
175
175
  * Check if type `T` is `string` or string literals.
176
176
  *
177
177
  * @return `expected` as `T` for type inspection.
178
178
  */
179
- string<T>(expected: IsString<T>): T
179
+ string<T>(expected: IsString<T>): T,
180
180
  /**
181
181
  * Check if type `T` is a `symbol`.
182
182
  *
183
183
  * @return `expected` as `T` for type inspection.
184
184
  */
185
- symbol<T>(expected: IsSymbol<T>): T
185
+ symbol<T>(expected: IsSymbol<T>): T,
186
186
  /**
187
187
  * Check if type `T` is a *tuple*.
188
188
  *
189
189
  * @return `expected` as `T` for type inspection.
190
190
  */
191
- tuple<T>(expected: IsTuple<T>): T
191
+ tuple<T>(expected: IsTuple<T>): T,
192
192
  /**
193
193
  * Check if type `T` is exactly `undefined`.
194
194
  *
195
195
  * @return `expected` as `T` for type inspection.
196
196
  */
197
- undefined<T>(expected: IsUndefined<T>): T
197
+ undefined<T>(expected: IsUndefined<T>): T,
198
198
  // hasUndefined<T>(expected: CanAssign<T, undefined>): T
199
199
  /**
200
200
  * Check if type `T` is exactly `unknown`.
201
201
  *
202
202
  * @return `expected` as `T` for type inspection.
203
203
  */
204
- unknown<T>(expected: IsUnknown<T>): T
204
+ unknown<T>(expected: IsUnknown<T>): T,
205
205
  /**
206
206
  * Check if type `T` is exactly `void`.
207
207
  *
208
208
  * @return `expected` as `T` for type inspection.
209
209
  */
210
- void<T>(expected: IsVoid<T>): T
210
+ void<T>(expected: IsVoid<T>): T,
211
211
  /**
212
212
  * A quick way to inspect a type.
213
213
  *
@@ -248,25 +248,68 @@ export const testType = new Proxy({} as TestType, {
248
248
  })
249
249
 
250
250
  export type InspectedType<T> = {
251
- value: T
252
- extends_any: T extends any ? true : false
253
- extends_unknown: T extends unknown ? true : false
254
- extends_void: T extends void ? true : false
255
- extends_never: T extends never ? true : false
256
- extends_undefined: T extends undefined ? true : false
257
- extends_null: T extends null ? true : false
258
- extends_boolean: T extends boolean ? true : false
259
- extends_true: T extends true ? true : false
260
- extends_false: T extends false ? true : false
261
- extends_number: T extends number ? true : false
262
- extends_1: T extends 1 ? true : false
263
- extends_bigint: T extends bigint ? true : false
264
- extends_1n: T extends 1n ? true : false
265
- extends_string: T extends string ? true : false
266
- extends_a: T extends 'a' ? true : false
267
- extends_symbol: T extends symbol ? true : false
268
- extends_object: T extends object ? true : false
269
- extends_function: T extends Function ? true : false
270
- extends_array_unknown: T extends unknown[] ? true : false
271
- extends_tuple_empty: T extends [] ? true : false
251
+ type: T,
252
+ extends<R>(): T extends R ? true : false,
253
+ extends_any: T extends any ? true : false,
254
+ extends_unknown: T extends unknown ? true : false,
255
+ extends_void: T extends void ? true : false,
256
+ extends_never: T extends never ? true : false,
257
+ extends_undefined: T extends undefined ? true : false,
258
+ extends_null: T extends null ? true : false,
259
+ extends_boolean: T extends boolean ? true : false,
260
+ extends_true: T extends true ? true : false,
261
+ extends_false: T extends false ? true : false,
262
+ extends_number: T extends number ? true : false,
263
+ extends_1: T extends 1 ? true : false,
264
+ extends_bigint: T extends bigint ? true : false,
265
+ extends_1n: T extends 1n ? true : false,
266
+ extends_string: T extends string ? true : false,
267
+ extends_a: T extends 'a' ? true : false,
268
+ extends_symbol: T extends symbol ? true : false,
269
+ extends_object: T extends object ? true : false,
270
+ extends_function: T extends Function ? true : false,
271
+ extends_array_unknown: T extends unknown[] ? true : false,
272
+ extends_tuple_empty: T extends [] ? true : false,
273
+ union<R>(): T | R,
274
+ union_any: T | any,
275
+ union_unknown: T | unknown,
276
+ union_void: T | void,
277
+ union_never: T | never,
278
+ union_undefined: T | undefined,
279
+ union_null: T | null,
280
+ union_boolean: T | boolean,
281
+ union_true: T | true,
282
+ union_false: T | false,
283
+ union_number: T | number,
284
+ union_1: T | 1,
285
+ union_bigint: T | bigint,
286
+ union_1n: T | 1n,
287
+ union_string: T | string,
288
+ union_a: T | 'a',
289
+ union_symbol: T | symbol,
290
+ union_object: T | object,
291
+ union_function: T | Function,
292
+ union_array_unknown: T | unknown[],
293
+ union_tuple_empty: T | [],
294
+ intersect<R>(): T & R,
295
+ intersect_any: T & any,
296
+ intersect_unknown: T & unknown,
297
+ intersect_void: T & void,
298
+ intersect_never: T & never,
299
+ intersect_undefined: T & undefined,
300
+ intersect_null: T & null,
301
+ intersect_boolean: T & boolean,
302
+ intersect_true: T & true,
303
+ intersect_false: T & false,
304
+ intersect_number: T & number,
305
+ intersect_1: T & 1,
306
+ intersect_bigint: T & bigint,
307
+ intersect_1n: T & 1n,
308
+ intersect_string: T & string,
309
+ intersect_a: T & 'a',
310
+ intersect_symbol: T & symbol,
311
+ intersect_object: T & object,
312
+ intersect_function: T & Function,
313
+ intersect_array_unknown: T & unknown[],
314
+ intersect_tuple_empty: T & []
272
315
  }
@@ -0,0 +1,55 @@
1
+ import type { NotNeverType } from '../never/never_type.js'
2
+ import type { KeyTypes } from '../object/KeyTypes.js'
3
+ import type { Tail } from './tail.js'
4
+
5
+ /**
6
+ * ⚗️ *transform*
7
+ *
8
+ * Gets the common property keys of the elements in tuple `T`.
9
+ *
10
+ * ```ts
11
+ * import { CommonPropKeys } from 'type-plus'
12
+ *
13
+ * type R = CommonPropKeys<[{ a: number }, { b: number }]> // never
14
+ * type R = CommonPropKeys<[{ a: number, c: 1 }, { b: number, c: 2 }]> // 'c'
15
+ * ```
16
+ */
17
+ export type CommonPropKeys<
18
+ T extends Record<KeyTypes, unknown>[],
19
+ Cases extends {
20
+ array?: unknown,
21
+ no_common_keys?: unknown
22
+ } = {
23
+ array: T extends Array<infer R extends Record<KeyTypes, unknown>> ? keyof R : never,
24
+ no_common_keys: never
25
+ }
26
+ > = number extends T['length']
27
+ ? Cases['array']
28
+ : (
29
+ T['length'] extends 0
30
+ ? Cases['no_common_keys']
31
+ : (
32
+ T['length'] extends 1
33
+ ? keyof T[0]
34
+ : (
35
+ T['length'] extends 2
36
+ ? (
37
+ keyof T[0] & keyof T[1] extends infer R
38
+ ? NotNeverType<R, R, Cases['no_common_keys']>
39
+ : never
40
+ )
41
+ : (
42
+ keyof T[0] & keyof T[1] & CommonPropKeys<Tail<Tail<T>>> extends infer R
43
+ ? NotNeverType<R, R, Cases['no_common_keys']>
44
+ : never
45
+ )
46
+ )
47
+ )
48
+ )
49
+
50
+ /**
51
+ * Gets the common property keys of the elements in `A`.
52
+ *
53
+ * @deprecated Please use `CommonPropKeys` instead.
54
+ */
55
+ export type CommonKeys<A extends Record<KeyTypes, any>[]> = CommonPropKeys<A>
@@ -28,15 +28,15 @@ export type ToTuple<R extends any[], S extends number[], X = any> = S['length']
28
28
  type DigitToTuple<T = 1> = {
29
29
  [k in number]: any[]
30
30
  } & {
31
- 0: []
32
- 1: [T]
33
- 2: [T, T]
34
- 3: [T, T, T]
35
- 4: [T, T, T, T]
36
- 5: [T, T, T, T, T]
37
- 6: [T, T, T, T, T, T]
38
- 7: [T, T, T, T, T, T, T]
39
- 8: [T, T, T, T, T, T, T, T]
31
+ 0: [],
32
+ 1: [T],
33
+ 2: [T, T],
34
+ 3: [T, T, T],
35
+ 4: [T, T, T, T],
36
+ 5: [T, T, T, T, T],
37
+ 6: [T, T, T, T, T, T],
38
+ 7: [T, T, T, T, T, T, T],
39
+ 8: [T, T, T, T, T, T, T, T],
40
40
  9: [T, T, T, T, T, T, T, T, T]
41
41
  }
42
42
  type Multi10<C extends any[]> = [...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C, ...C]