type-plus 7.4.0 → 7.6.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 (202) hide show
  1. package/README.md +81 -92
  2. package/cjs/array/array.entries.d.ts +4 -3
  3. package/cjs/array/array.entries.d.ts.map +1 -1
  4. package/cjs/array/array_index.d.ts +4 -1
  5. package/cjs/array/array_index.d.ts.map +1 -1
  6. package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
  7. package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
  8. package/cjs/array/array_plus.common_prop_keys.js +3 -0
  9. package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
  10. package/cjs/array/array_plus.d.ts +6 -3
  11. package/cjs/array/array_plus.d.ts.map +1 -1
  12. package/cjs/array/array_plus.drop_match.d.ts +4 -0
  13. package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
  14. package/cjs/array/array_plus.drop_match.js +3 -0
  15. package/cjs/array/array_plus.drop_match.js.map +1 -0
  16. package/cjs/array/array_plus.element_match.d.ts +44 -0
  17. package/cjs/array/array_plus.element_match.d.ts.map +1 -0
  18. package/cjs/array/array_plus.element_match.js +3 -0
  19. package/cjs/array/array_plus.element_match.js.map +1 -0
  20. package/cjs/array/array_plus.find.d.ts +57 -0
  21. package/cjs/array/array_plus.find.d.ts.map +1 -0
  22. package/cjs/array/array_plus.find.js +3 -0
  23. package/cjs/array/array_plus.find.js.map +1 -0
  24. package/cjs/array/array_plus.split_at.d.ts +20 -15
  25. package/cjs/array/array_plus.split_at.d.ts.map +1 -1
  26. package/cjs/array/find_first.d.ts +62 -0
  27. package/cjs/array/find_first.d.ts.map +1 -0
  28. package/cjs/array/{array.find.js → find_first.js} +1 -1
  29. package/cjs/array/find_first.js.map +1 -0
  30. package/cjs/array/head.d.ts +18 -6
  31. package/cjs/array/head.d.ts.map +1 -1
  32. package/cjs/array/last.d.ts +17 -6
  33. package/cjs/array/last.d.ts.map +1 -1
  34. package/cjs/assertion/assert_type.d.ts +4 -1
  35. package/cjs/assertion/assert_type.d.ts.map +1 -1
  36. package/cjs/assertion/assert_type.js.map +1 -1
  37. package/cjs/index.d.ts +5 -2
  38. package/cjs/index.d.ts.map +1 -1
  39. package/cjs/index.js.map +1 -1
  40. package/cjs/never/never_type.d.ts +11 -0
  41. package/cjs/never/never_type.d.ts.map +1 -1
  42. package/cjs/object/index.d.ts +0 -1
  43. package/cjs/object/index.d.ts.map +1 -1
  44. package/cjs/object/index.js.map +1 -1
  45. package/cjs/testing/test_type.d.ts +277 -276
  46. package/cjs/testing/test_type.d.ts.map +1 -1
  47. package/cjs/testing/test_type.js.map +1 -1
  48. package/cjs/tuple/common_prop_keys.d.ts +15 -10
  49. package/cjs/tuple/common_prop_keys.d.ts.map +1 -1
  50. package/cjs/tuple/drop.d.ts +45 -26
  51. package/cjs/tuple/drop.d.ts.map +1 -1
  52. package/cjs/tuple/drop.js.map +1 -1
  53. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  54. package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  55. package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
  56. package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  57. package/cjs/tuple/tuple_plus.d.ts +3 -0
  58. package/cjs/tuple/tuple_plus.d.ts.map +1 -1
  59. package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
  60. package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  61. package/cjs/tuple/tuple_plus.drop_match.js +3 -0
  62. package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
  63. package/cjs/tuple/tuple_plus.filter.d.ts +2 -2
  64. package/cjs/tuple/tuple_plus.find.d.ts +64 -0
  65. package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
  66. package/cjs/tuple/tuple_plus.find.js +3 -0
  67. package/cjs/tuple/tuple_plus.find.js.map +1 -0
  68. package/cjs/tuple/tuple_plus.pad_start.d.ts +7 -6
  69. package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  70. package/cjs/tuple/tuple_type.d.ts +41 -23
  71. package/cjs/tuple/tuple_type.d.ts.map +1 -1
  72. package/cjs/union/union.d.ts +33 -0
  73. package/cjs/union/union.d.ts.map +1 -0
  74. package/cjs/union/union.js +3 -0
  75. package/cjs/union/union.js.map +1 -0
  76. package/cjs/unknown/unknown_type.d.ts +12 -0
  77. package/cjs/unknown/unknown_type.d.ts.map +1 -1
  78. package/cjs/utils/options.d.ts +10 -0
  79. package/cjs/utils/options.d.ts.map +1 -0
  80. package/cjs/utils/options.js +3 -0
  81. package/cjs/utils/options.js.map +1 -0
  82. package/esm/array/array.entries.d.ts +4 -3
  83. package/esm/array/array.entries.d.ts.map +1 -1
  84. package/esm/array/array_index.d.ts +4 -1
  85. package/esm/array/array_index.d.ts.map +1 -1
  86. package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
  87. package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
  88. package/esm/array/array_plus.common_prop_keys.js +2 -0
  89. package/esm/array/array_plus.common_prop_keys.js.map +1 -0
  90. package/esm/array/array_plus.d.ts +6 -3
  91. package/esm/array/array_plus.d.ts.map +1 -1
  92. package/esm/array/array_plus.drop_match.d.ts +4 -0
  93. package/esm/array/array_plus.drop_match.d.ts.map +1 -0
  94. package/esm/array/array_plus.drop_match.js +2 -0
  95. package/esm/array/array_plus.drop_match.js.map +1 -0
  96. package/esm/array/array_plus.element_match.d.ts +44 -0
  97. package/esm/array/array_plus.element_match.d.ts.map +1 -0
  98. package/esm/array/array_plus.element_match.js +2 -0
  99. package/esm/array/array_plus.element_match.js.map +1 -0
  100. package/esm/array/array_plus.find.d.ts +57 -0
  101. package/esm/array/array_plus.find.d.ts.map +1 -0
  102. package/esm/array/array_plus.find.js +2 -0
  103. package/esm/array/array_plus.find.js.map +1 -0
  104. package/esm/array/array_plus.split_at.d.ts +20 -15
  105. package/esm/array/array_plus.split_at.d.ts.map +1 -1
  106. package/esm/array/find_first.d.ts +62 -0
  107. package/esm/array/find_first.d.ts.map +1 -0
  108. package/esm/array/find_first.js +2 -0
  109. package/esm/array/find_first.js.map +1 -0
  110. package/esm/array/head.d.ts +18 -6
  111. package/esm/array/head.d.ts.map +1 -1
  112. package/esm/array/last.d.ts +17 -6
  113. package/esm/array/last.d.ts.map +1 -1
  114. package/esm/assertion/assert_type.d.ts +4 -1
  115. package/esm/assertion/assert_type.d.ts.map +1 -1
  116. package/esm/assertion/assert_type.js.map +1 -1
  117. package/esm/index.d.ts +5 -2
  118. package/esm/index.d.ts.map +1 -1
  119. package/esm/index.js.map +1 -1
  120. package/esm/never/never_type.d.ts +11 -0
  121. package/esm/never/never_type.d.ts.map +1 -1
  122. package/esm/object/index.d.ts +0 -1
  123. package/esm/object/index.d.ts.map +1 -1
  124. package/esm/object/index.js.map +1 -1
  125. package/esm/testing/test_type.d.ts +277 -276
  126. package/esm/testing/test_type.d.ts.map +1 -1
  127. package/esm/testing/test_type.js.map +1 -1
  128. package/esm/tuple/common_prop_keys.d.ts +15 -10
  129. package/esm/tuple/common_prop_keys.d.ts.map +1 -1
  130. package/esm/tuple/drop.d.ts +45 -26
  131. package/esm/tuple/drop.d.ts.map +1 -1
  132. package/esm/tuple/drop.js.map +1 -1
  133. package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
  134. package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
  135. package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
  136. package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
  137. package/esm/tuple/tuple_plus.d.ts +3 -0
  138. package/esm/tuple/tuple_plus.d.ts.map +1 -1
  139. package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
  140. package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
  141. package/esm/tuple/tuple_plus.drop_match.js +2 -0
  142. package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
  143. package/esm/tuple/tuple_plus.filter.d.ts +2 -2
  144. package/esm/tuple/tuple_plus.find.d.ts +64 -0
  145. package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
  146. package/esm/tuple/tuple_plus.find.js +2 -0
  147. package/esm/tuple/tuple_plus.find.js.map +1 -0
  148. package/esm/tuple/tuple_plus.pad_start.d.ts +7 -6
  149. package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
  150. package/esm/tuple/tuple_type.d.ts +41 -23
  151. package/esm/tuple/tuple_type.d.ts.map +1 -1
  152. package/esm/union/union.d.ts +33 -0
  153. package/esm/union/union.d.ts.map +1 -0
  154. package/esm/union/union.js +2 -0
  155. package/esm/union/union.js.map +1 -0
  156. package/esm/unknown/unknown_type.d.ts +12 -0
  157. package/esm/unknown/unknown_type.d.ts.map +1 -1
  158. package/esm/utils/options.d.ts +10 -0
  159. package/esm/utils/options.d.ts.map +1 -0
  160. package/esm/utils/options.js +2 -0
  161. package/esm/utils/options.js.map +1 -0
  162. package/package.json +12 -1
  163. package/ts/array/array.entries.ts +4 -2
  164. package/ts/array/array_index.ts +33 -23
  165. package/ts/array/array_plus.common_prop_keys.ts +35 -0
  166. package/ts/array/array_plus.drop_match.ts +16 -0
  167. package/ts/array/array_plus.element_match.ts +61 -0
  168. package/ts/array/array_plus.find.ts +71 -0
  169. package/ts/array/array_plus.split_at.ts +52 -23
  170. package/ts/array/array_plus.ts +6 -3
  171. package/ts/array/find_first.ts +71 -0
  172. package/ts/array/head.ts +28 -6
  173. package/ts/array/last.ts +26 -6
  174. package/ts/array/readme.md +152 -32
  175. package/ts/assertion/assert_type.ts +4 -1
  176. package/ts/assertion/readme.md +3 -2
  177. package/ts/index.ts +5 -5
  178. package/ts/never/never_type.ts +13 -0
  179. package/ts/object/index.ts +0 -1
  180. package/ts/testing/test_type.ts +279 -277
  181. package/ts/tuple/common_prop_keys.ts +18 -32
  182. package/ts/tuple/drop.ts +61 -60
  183. package/ts/tuple/readme.md +178 -39
  184. package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
  185. package/ts/tuple/tuple_plus.drop_match.ts +20 -0
  186. package/ts/tuple/tuple_plus.filter.ts +2 -2
  187. package/ts/tuple/tuple_plus.find.ts +88 -0
  188. package/ts/tuple/tuple_plus.pad_start.ts +28 -25
  189. package/ts/tuple/tuple_plus.ts +3 -0
  190. package/ts/tuple/tuple_type.ts +67 -25
  191. package/ts/union/readme.md +81 -0
  192. package/ts/union/union.ts +37 -0
  193. package/ts/unknown/unknown_type.ts +13 -0
  194. package/ts/utils/options.ts +10 -0
  195. package/cjs/array/array.find.d.ts +0 -23
  196. package/cjs/array/array.find.d.ts.map +0 -1
  197. package/cjs/array/array.find.js.map +0 -1
  198. package/esm/array/array.find.d.ts +0 -23
  199. package/esm/array/array.find.d.ts.map +0 -1
  200. package/esm/array/array.find.js +0 -2
  201. package/esm/array/array.find.js.map +0 -1
  202. package/ts/array/array.find.ts +0 -34
@@ -23,215 +23,284 @@ import type { IsUndefined } from '../undefined/undefined_type.js'
23
23
  import type { IsUnknown } from '../unknown/unknown_type.js'
24
24
  import type { IsVoid } from '../void/void_type.js'
25
25
 
26
- interface TestType {
27
- /**
28
- * Check if type `A` is equal to type `B` and `C`.
29
- *
30
- * @return `expected` as `A` for type inspection.
31
- */
32
- equal<A, B, C>(expected: IsEqual<A, B> & IsEqual<A, C>): A,
33
- /**
34
- * Check if type `A` is equal to type `B`.
35
- *
36
- * @return `expected` as `A` for type inspection.
37
- */
38
- equal<A, B>(expected: IsEqual<A, B>): A,
39
- /**
40
- * Check if `A` can assign to `B`.
41
- *
42
- * If `A` is a union,
43
- * the check is distributive.
44
- *
45
- * Meaning the result can be `boolean`,
46
- * meaning both `true` and `false` will pass.
47
- *
48
- * If you want to avoid the distributivity,
49
- * use `testType.strictCanAssign()` instead.
50
- *
51
- * @example
52
- * ```ts
53
- * testType.canAssign<123, number> // true
54
- *
55
- * testType.canAssign<number | string, number> // boolean
56
- * ```
57
- *
58
- * @return `expected` as `A` for type inspection.
59
- */
60
- canAssign<A, B>(expected: CanAssign<A, B>): A,
61
- /**
62
- * Check if `A` can fully assign to `B`.
63
- *
64
- * This checks all branches in an union `A` are assignable to `B`.
65
- *
66
- * @example
67
- * ```ts
68
- * testType.strictCanAssign<number | string, number | string> // true
69
- *
70
- * testType.strictCanAssign<number | string, number> // false
71
- * ```
72
- *
73
- * @return `expected` as `A` for type inspection.
74
- */
75
- strictCanAssign<A, B>(expected: StrictCanAssign<A, B>): A,
76
- /**
77
- * Check if type `T` is exactly `any`.
78
- *
79
- * @return `expected` as `T` for type inspection.
80
- */
81
- any<T>(expected: IsAny<T>): T,
82
- /**
83
- * Check if type `T` is exactly `array`.
84
- *
85
- * @return `expected` as `T` for type inspection.
86
- */
87
- array<T>(expected: IsArray<T>): T,
88
- /**
89
- * Check if type `T` is exactly `bigint`.
90
- *
91
- * @return `expected` as `T` for type inspection.
92
- */
93
- strictBigint<T>(expected: IsStrictBigint<T>): T,
94
- /**
95
- * Check if type `T` is `bigint` or bigint literals.
96
- *
97
- * @return `expected` as `T` for type inspection.
98
- */
99
- bigint<T>(expected: IsBigint<T>): T,
100
- /**
101
- * Check if type `T` is exactly `boolean`.
102
- *
103
- * @return `expected` as `T` for type inspection.
104
- */
105
- strictBoolean<T>(expected: IsStrictBoolean<T>): T,
106
- /**
107
- * Check if type `T` is `boolean` and boolean literals.
108
- *
109
- * @return `expected` as `T` for type inspection.
110
- */
111
- boolean<T>(expected: IsBoolean<T>): T,
112
- /**
113
- * Check if type `T` is exactly `true`.
114
- *
115
- * @return `expected` as `T` for type inspection.
116
- */
117
- true<T>(expected: IsTrue<T>): T,
118
- /**
119
- * Check if type `T` is exactly `false`.
120
- *
121
- * @return `expected` as `T` for type inspection.
122
- */
123
- false<T>(expected: IsFalse<T>): T,
124
- /**
125
- * Check if type `T` is exactly `boolean`.
126
- *
127
- * @return `expected` as `T` for type inspection.
128
- */
129
- strictFunction<T>(expected: IsStrictFunction<T>): T,
130
- /**
131
- * Check if type `T` is `boolean` and boolean literals.
132
- *
133
- * @return `expected` as `T` for type inspection.
134
- */
135
- function<T>(expected: IsFunction<T>): T,
136
- /**
137
- * Check if type `T` is exactly `never`.
138
- *
139
- * @return `expected` as `T` for type inspection.
140
- */
141
- never<T>(expected: IsNever<T>): T,
142
- /**
143
- * Check if type `T` is exactly `null`.
144
- *
145
- * @return `expected` as `T` for type inspection.
146
- */
147
- null<T>(expected: IsNull<T>): T,
148
- /**
149
- * Check if type `T` is exactly `number`.
150
- *
151
- * @return `expected` as `T` for type inspection.
152
- */
153
- strictNumber<T>(expected: IsStrictNumber<T>): T,
154
- /**
155
- * Check if type `T` is `number` or number literals.
156
- *
157
- * @return `expected` as `T` for type inspection.
158
- */
159
- number<T>(expected: IsNumber<T>): T,
160
- /**
161
- * Check if type `T` is `object`.
162
- *
163
- * Note that `Function`, `Array`, and *tuple* are also `object`.
164
- *
165
- * @return `expected` as `T` for type inspection.
166
- */
167
- object<T>(expected: IsObject<T>): T,
168
- /**
169
- * Check if type `T` is exactly `string`.
170
- *
171
- * @return `expected` as `T` for type inspection.
172
- */
173
- strictString<T>(expected: IsStrictString<T>): T,
174
- /**
175
- * Check if type `T` is `string` or string literals.
176
- *
177
- * @return `expected` as `T` for type inspection.
178
- */
179
- string<T>(expected: IsString<T>): T,
180
- /**
181
- * Check if type `T` is a `symbol`.
182
- *
183
- * @return `expected` as `T` for type inspection.
184
- */
185
- symbol<T>(expected: IsSymbol<T>): T,
186
- /**
187
- * Check if type `T` is a *tuple*.
188
- *
189
- * @return `expected` as `T` for type inspection.
190
- */
191
- tuple<T>(expected: IsTuple<T>): T,
192
- /**
193
- * Check if type `T` is exactly `undefined`.
194
- *
195
- * @return `expected` as `T` for type inspection.
196
- */
197
- undefined<T>(expected: IsUndefined<T>): T,
198
- // hasUndefined<T>(expected: CanAssign<T, undefined>): T
199
- /**
200
- * Check if type `T` is exactly `unknown`.
201
- *
202
- * @return `expected` as `T` for type inspection.
203
- */
204
- unknown<T>(expected: IsUnknown<T>): T,
205
- /**
206
- * Check if type `T` is exactly `void`.
207
- *
208
- * @return `expected` as `T` for type inspection.
209
- */
210
- void<T>(expected: IsVoid<T>): T,
211
- /**
212
- * A quick way to inspect a type.
213
- *
214
- * The handler receives a `InspectedType` object.
215
- * It contains `value` which is typed to `T`,
216
- * and many other properties to inspect the behavior of `T`.
217
- *
218
- * The handler is not being call,
219
- * it is use to hold the type in value for inspection.
220
- *
221
- * 🧪 *testing*
222
- * 🦴 *utilities*
223
- *
224
- * @example
225
- * ```ts
226
- * testType.inspect<SomeType>(t => {
227
- * type T = typeof t.value // resolve and inspect the type `T`
228
- * t.extend_boolean // result of `T extends boolean`
229
- * })
230
- * ```
231
- *
232
- * After trying out the type, remove the line.
233
- */
234
- inspect<T>(handler: (t: InspectedType<T>) => unknown): T
26
+ export namespace testType {
27
+ export interface TestType {
28
+ /**
29
+ * Check if type `A` is equal to type `B` and `C`.
30
+ *
31
+ * @return `expected` as `A` for type inspection.
32
+ */
33
+ equal<A, B, C>(expected: IsEqual<A, B> & IsEqual<A, C>): A,
34
+ /**
35
+ * Check if type `A` is equal to type `B`.
36
+ *
37
+ * @return `expected` as `A` for type inspection.
38
+ */
39
+ equal<A, B>(expected: IsEqual<A, B>): A,
40
+ /**
41
+ * Check if `A` can assign to `B`.
42
+ *
43
+ * If `A` is a union,
44
+ * the check is distributive.
45
+ *
46
+ * Meaning the result can be `boolean`,
47
+ * meaning both `true` and `false` will pass.
48
+ *
49
+ * If you want to avoid the distributivity,
50
+ * use `testType.strictCanAssign()` instead.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * testType.canAssign<123, number> // true
55
+ *
56
+ * testType.canAssign<number | string, number> // boolean
57
+ * ```
58
+ *
59
+ * @return `expected` as `A` for type inspection.
60
+ */
61
+ canAssign<A, B>(expected: CanAssign<A, B>): A,
62
+ /**
63
+ * Check if `A` can fully assign to `B`.
64
+ *
65
+ * This checks all branches in an union `A` are assignable to `B`.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * testType.strictCanAssign<number | string, number | string> // true
70
+ *
71
+ * testType.strictCanAssign<number | string, number> // false
72
+ * ```
73
+ *
74
+ * @return `expected` as `A` for type inspection.
75
+ */
76
+ strictCanAssign<A, B>(expected: StrictCanAssign<A, B>): A,
77
+ /**
78
+ * Check if type `T` is exactly `any`.
79
+ *
80
+ * @return `expected` as `T` for type inspection.
81
+ */
82
+ any<T>(expected: IsAny<T>): T,
83
+ /**
84
+ * Check if type `T` is exactly `array`.
85
+ *
86
+ * @return `expected` as `T` for type inspection.
87
+ */
88
+ array<T>(expected: IsArray<T>): T,
89
+ /**
90
+ * Check if type `T` is exactly `bigint`.
91
+ *
92
+ * @return `expected` as `T` for type inspection.
93
+ */
94
+ strictBigint<T>(expected: IsStrictBigint<T>): T,
95
+ /**
96
+ * Check if type `T` is `bigint` or bigint literals.
97
+ *
98
+ * @return `expected` as `T` for type inspection.
99
+ */
100
+ bigint<T>(expected: IsBigint<T>): T,
101
+ /**
102
+ * Check if type `T` is exactly `boolean`.
103
+ *
104
+ * @return `expected` as `T` for type inspection.
105
+ */
106
+ strictBoolean<T>(expected: IsStrictBoolean<T>): T,
107
+ /**
108
+ * Check if type `T` is `boolean` and boolean literals.
109
+ *
110
+ * @return `expected` as `T` for type inspection.
111
+ */
112
+ boolean<T>(expected: IsBoolean<T>): T,
113
+ /**
114
+ * Check if type `T` is exactly `true`.
115
+ *
116
+ * @return `expected` as `T` for type inspection.
117
+ */
118
+ true<T>(expected: IsTrue<T>): T,
119
+ /**
120
+ * Check if type `T` is exactly `false`.
121
+ *
122
+ * @return `expected` as `T` for type inspection.
123
+ */
124
+ false<T>(expected: IsFalse<T>): T,
125
+ /**
126
+ * Check if type `T` is exactly `boolean`.
127
+ *
128
+ * @return `expected` as `T` for type inspection.
129
+ */
130
+ strictFunction<T>(expected: IsStrictFunction<T>): T,
131
+ /**
132
+ * Check if type `T` is `boolean` and boolean literals.
133
+ *
134
+ * @return `expected` as `T` for type inspection.
135
+ */
136
+ function<T>(expected: IsFunction<T>): T,
137
+ /**
138
+ * Check if type `T` is exactly `never`.
139
+ *
140
+ * @return `expected` as `T` for type inspection.
141
+ */
142
+ never<T>(expected: IsNever<T>): T,
143
+ /**
144
+ * Check if type `T` is exactly `null`.
145
+ *
146
+ * @return `expected` as `T` for type inspection.
147
+ */
148
+ null<T>(expected: IsNull<T>): T,
149
+ /**
150
+ * Check if type `T` is exactly `number`.
151
+ *
152
+ * @return `expected` as `T` for type inspection.
153
+ */
154
+ strictNumber<T>(expected: IsStrictNumber<T>): T,
155
+ /**
156
+ * Check if type `T` is `number` or number literals.
157
+ *
158
+ * @return `expected` as `T` for type inspection.
159
+ */
160
+ number<T>(expected: IsNumber<T>): T,
161
+ /**
162
+ * Check if type `T` is `object`.
163
+ *
164
+ * Note that `Function`, `Array`, and *tuple* are also `object`.
165
+ *
166
+ * @return `expected` as `T` for type inspection.
167
+ */
168
+ object<T>(expected: IsObject<T>): T,
169
+ /**
170
+ * Check if type `T` is exactly `string`.
171
+ *
172
+ * @return `expected` as `T` for type inspection.
173
+ */
174
+ strictString<T>(expected: IsStrictString<T>): T,
175
+ /**
176
+ * Check if type `T` is `string` or string literals.
177
+ *
178
+ * @return `expected` as `T` for type inspection.
179
+ */
180
+ string<T>(expected: IsString<T>): T,
181
+ /**
182
+ * Check if type `T` is a `symbol`.
183
+ *
184
+ * @return `expected` as `T` for type inspection.
185
+ */
186
+ symbol<T>(expected: IsSymbol<T>): T,
187
+ /**
188
+ * Check if type `T` is a *tuple*.
189
+ *
190
+ * @return `expected` as `T` for type inspection.
191
+ */
192
+ tuple<T>(expected: IsTuple<T>): T,
193
+ /**
194
+ * Check if type `T` is exactly `undefined`.
195
+ *
196
+ * @return `expected` as `T` for type inspection.
197
+ */
198
+ undefined<T>(expected: IsUndefined<T>): T,
199
+ // hasUndefined<T>(expected: CanAssign<T, undefined>): T
200
+ /**
201
+ * Check if type `T` is exactly `unknown`.
202
+ *
203
+ * @return `expected` as `T` for type inspection.
204
+ */
205
+ unknown<T>(expected: IsUnknown<T>): T,
206
+ /**
207
+ * Check if type `T` is exactly `void`.
208
+ *
209
+ * @return `expected` as `T` for type inspection.
210
+ */
211
+ void<T>(expected: IsVoid<T>): T,
212
+ /**
213
+ * A quick way to inspect a type.
214
+ *
215
+ * The handler receives a `InspectedType` object.
216
+ * It contains `value` which is typed to `T`,
217
+ * and many other properties to inspect the behavior of `T`.
218
+ *
219
+ * The handler is not being call,
220
+ * it is use to hold the type in value for inspection.
221
+ *
222
+ * 🧪 *testing*
223
+ * 🦴 *utilities*
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * testType.inspect<SomeType>(t => {
228
+ * type T = typeof t.value // resolve and inspect the type `T`
229
+ * t.extend_boolean // result of `T extends boolean`
230
+ * })
231
+ * ```
232
+ *
233
+ * After trying out the type, remove the line.
234
+ */
235
+ inspect<T>(handler: (t: InspectedType<T>) => unknown): T
236
+ }
237
+
238
+ export type InspectedType<T> = {
239
+ type: T,
240
+ extends<R>(): T extends R ? true : false,
241
+ extends_any: T extends any ? true : false,
242
+ extends_unknown: T extends unknown ? true : false,
243
+ extends_void: T extends void ? true : false,
244
+ extends_never: T extends never ? true : false,
245
+ extends_undefined: T extends undefined ? true : false,
246
+ extends_null: T extends null ? true : false,
247
+ extends_boolean: T extends boolean ? true : false,
248
+ extends_true: T extends true ? true : false,
249
+ extends_false: T extends false ? true : false,
250
+ extends_number: T extends number ? true : false,
251
+ extends_1: T extends 1 ? true : false,
252
+ extends_bigint: T extends bigint ? true : false,
253
+ extends_1n: T extends 1n ? true : false,
254
+ extends_string: T extends string ? true : false,
255
+ extends_a: T extends 'a' ? true : false,
256
+ extends_symbol: T extends symbol ? true : false,
257
+ extends_object: T extends object ? true : false,
258
+ extends_function: T extends Function ? true : false,
259
+ extends_array_unknown: T extends unknown[] ? true : false,
260
+ extends_tuple_empty: T extends [] ? true : false,
261
+ union<R>(): T | R,
262
+ union_any: T | any,
263
+ union_unknown: T | unknown,
264
+ union_void: T | void,
265
+ union_never: T | never,
266
+ union_undefined: T | undefined,
267
+ union_null: T | null,
268
+ union_boolean: T | boolean,
269
+ union_true: T | true,
270
+ union_false: T | false,
271
+ union_number: T | number,
272
+ union_1: T | 1,
273
+ union_bigint: T | bigint,
274
+ union_1n: T | 1n,
275
+ union_string: T | string,
276
+ union_a: T | 'a',
277
+ union_symbol: T | symbol,
278
+ union_object: T | object,
279
+ union_function: T | Function,
280
+ union_array_unknown: T | unknown[],
281
+ union_tuple_empty: T | [],
282
+ intersect<R>(): T & R,
283
+ intersect_any: T & any,
284
+ intersect_unknown: T & unknown,
285
+ intersect_void: T & void,
286
+ intersect_never: T & never,
287
+ intersect_undefined: T & undefined,
288
+ intersect_null: T & null,
289
+ intersect_boolean: T & boolean,
290
+ intersect_true: T & true,
291
+ intersect_false: T & false,
292
+ intersect_number: T & number,
293
+ intersect_1: T & 1,
294
+ intersect_bigint: T & bigint,
295
+ intersect_1n: T & 1n,
296
+ intersect_string: T & string,
297
+ intersect_a: T & 'a',
298
+ intersect_symbol: T & symbol,
299
+ intersect_object: T & object,
300
+ intersect_function: T & Function,
301
+ intersect_array_unknown: T & unknown[],
302
+ intersect_tuple_empty: T & []
303
+ }
235
304
  }
236
305
 
237
306
  /**
@@ -241,75 +310,8 @@ interface TestType {
241
310
  * The return value is the input `expected` parameter asserted as the first type parameter,
242
311
  * so that the type can be further inspected.
243
312
  */
244
- export const testType = new Proxy({} as TestType, {
313
+ export const testType = new Proxy({} as testType.TestType, {
245
314
  get(_target, _prop, _receiver) {
246
315
  return (expected: unknown) => expected
247
316
  }
248
317
  })
249
-
250
- export type InspectedType<T> = {
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 & []
315
- }
@@ -1,51 +1,37 @@
1
- import type { NotNeverType } from '../never/never_type.js'
1
+ import type { CommonPropKeys as ArrayCommonPropKeys } from '../array/array_plus.common_prop_keys.js'
2
2
  import type { KeyTypes } from '../object/KeyTypes.js'
3
- import type { Tail } from './tail.js'
3
+ import type { CommonPropKeys as TupleCommonPropKeys } from './tuple_plus.common_prop_keys.js'
4
4
 
5
5
  /**
6
6
  * ⚗️ *transform*
7
+ * 🔢 *customization*
7
8
  *
8
- * Gets the common property keys of the elements in tuple `T`.
9
+ * Gets the common property keys of the elements in tuple or array `T`.
9
10
  *
11
+ * @example
10
12
  * ```ts
11
13
  * import { CommonPropKeys } from 'type-plus'
12
14
  *
13
15
  * type R = CommonPropKeys<[{ a: number }, { b: number }]> // never
14
16
  * type R = CommonPropKeys<[{ a: number, c: 1 }, { b: number, c: 2 }]> // 'c'
15
17
  * ```
18
+ *
19
+ * @typeParam Options['caseNever'] Return type when `T` is `never`.
20
+ * Default to `never`.
16
21
  */
17
22
  export type CommonPropKeys<
18
23
  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
24
+ Options extends CommonPropKeys.Options = CommonPropKeys.DefaultOptions
25
+ > = number extends T['length'] ? ArrayCommonPropKeys<T> : TupleCommonPropKeys<T, Options>
26
+
27
+
28
+ export namespace CommonPropKeys {
29
+ export interface Options extends TupleCommonPropKeys.Options {
30
+ }
31
+
32
+ export interface DefaultOptions extends TupleCommonPropKeys.DefaultOptions {
25
33
  }
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
- )
34
+ }
49
35
 
50
36
  /**
51
37
  * Gets the common property keys of the elements in `A`.