type-plus 7.4.0 → 7.5.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.
- package/README.md +81 -92
- package/cjs/array/array.entries.d.ts +4 -3
- package/cjs/array/array.entries.d.ts.map +1 -1
- package/cjs/array/array_plus.common_prop_keys.d.ts +27 -0
- package/cjs/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/array/array_plus.common_prop_keys.js +3 -0
- package/cjs/array/array_plus.common_prop_keys.js.map +1 -0
- package/cjs/array/array_plus.d.ts +6 -3
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.drop_match.d.ts +4 -0
- package/cjs/array/array_plus.drop_match.d.ts.map +1 -0
- package/cjs/array/array_plus.drop_match.js +3 -0
- package/cjs/array/array_plus.drop_match.js.map +1 -0
- package/cjs/array/array_plus.element_match.d.ts +44 -0
- package/cjs/array/array_plus.element_match.d.ts.map +1 -0
- package/cjs/array/array_plus.element_match.js +3 -0
- package/cjs/array/array_plus.element_match.js.map +1 -0
- package/cjs/array/array_plus.find.d.ts +57 -0
- package/cjs/array/array_plus.find.d.ts.map +1 -0
- package/cjs/array/array_plus.find.js +3 -0
- package/cjs/array/array_plus.find.js.map +1 -0
- package/cjs/array/find_first.d.ts +62 -0
- package/cjs/array/find_first.d.ts.map +1 -0
- package/cjs/array/{array.find.js → find_first.js} +1 -1
- package/cjs/array/find_first.js.map +1 -0
- package/cjs/array/head.d.ts +18 -6
- package/cjs/array/head.d.ts.map +1 -1
- package/cjs/array/last.d.ts +17 -6
- package/cjs/array/last.d.ts.map +1 -1
- package/cjs/assertion/assert_type.d.ts +4 -1
- package/cjs/assertion/assert_type.d.ts.map +1 -1
- package/cjs/assertion/assert_type.js.map +1 -1
- package/cjs/index.d.ts +5 -2
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/never/never_type.d.ts +11 -0
- package/cjs/never/never_type.d.ts.map +1 -1
- package/cjs/object/index.d.ts +0 -1
- package/cjs/object/index.d.ts.map +1 -1
- package/cjs/object/index.js.map +1 -1
- package/cjs/testing/test_type.d.ts +277 -276
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/testing/test_type.js.map +1 -1
- package/cjs/tuple/common_prop_keys.d.ts +15 -10
- package/cjs/tuple/common_prop_keys.d.ts.map +1 -1
- package/cjs/tuple/drop.d.ts +45 -26
- package/cjs/tuple/drop.d.ts.map +1 -1
- package/cjs/tuple/drop.js.map +1 -1
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js +3 -0
- package/cjs/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/cjs/tuple/tuple_plus.d.ts +3 -0
- package/cjs/tuple/tuple_plus.d.ts.map +1 -1
- package/cjs/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/cjs/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.drop_match.js +3 -0
- package/cjs/tuple/tuple_plus.drop_match.js.map +1 -0
- package/cjs/tuple/tuple_plus.filter.d.ts +2 -2
- package/cjs/tuple/tuple_plus.find.d.ts +64 -0
- package/cjs/tuple/tuple_plus.find.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.find.js +3 -0
- package/cjs/tuple/tuple_plus.find.js.map +1 -0
- package/cjs/tuple/tuple_plus.pad_start.d.ts +7 -6
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/cjs/tuple/tuple_type.d.ts +41 -23
- package/cjs/tuple/tuple_type.d.ts.map +1 -1
- package/cjs/union/union.d.ts +33 -0
- package/cjs/union/union.d.ts.map +1 -0
- package/cjs/union/union.js +3 -0
- package/cjs/union/union.js.map +1 -0
- package/cjs/unknown/unknown_type.d.ts +12 -0
- package/cjs/unknown/unknown_type.d.ts.map +1 -1
- package/cjs/utils/options.d.ts +10 -0
- package/cjs/utils/options.d.ts.map +1 -0
- package/cjs/utils/options.js +3 -0
- package/cjs/utils/options.js.map +1 -0
- package/esm/array/array.entries.d.ts +4 -3
- package/esm/array/array.entries.d.ts.map +1 -1
- package/esm/array/array_plus.common_prop_keys.d.ts +27 -0
- package/esm/array/array_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/array/array_plus.common_prop_keys.js +2 -0
- package/esm/array/array_plus.common_prop_keys.js.map +1 -0
- package/esm/array/array_plus.d.ts +6 -3
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.drop_match.d.ts +4 -0
- package/esm/array/array_plus.drop_match.d.ts.map +1 -0
- package/esm/array/array_plus.drop_match.js +2 -0
- package/esm/array/array_plus.drop_match.js.map +1 -0
- package/esm/array/array_plus.element_match.d.ts +44 -0
- package/esm/array/array_plus.element_match.d.ts.map +1 -0
- package/esm/array/array_plus.element_match.js +2 -0
- package/esm/array/array_plus.element_match.js.map +1 -0
- package/esm/array/array_plus.find.d.ts +57 -0
- package/esm/array/array_plus.find.d.ts.map +1 -0
- package/esm/array/array_plus.find.js +2 -0
- package/esm/array/array_plus.find.js.map +1 -0
- package/esm/array/find_first.d.ts +62 -0
- package/esm/array/find_first.d.ts.map +1 -0
- package/esm/array/find_first.js +2 -0
- package/esm/array/find_first.js.map +1 -0
- package/esm/array/head.d.ts +18 -6
- package/esm/array/head.d.ts.map +1 -1
- package/esm/array/last.d.ts +17 -6
- package/esm/array/last.d.ts.map +1 -1
- package/esm/assertion/assert_type.d.ts +4 -1
- package/esm/assertion/assert_type.d.ts.map +1 -1
- package/esm/assertion/assert_type.js.map +1 -1
- package/esm/index.d.ts +5 -2
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js.map +1 -1
- package/esm/never/never_type.d.ts +11 -0
- package/esm/never/never_type.d.ts.map +1 -1
- package/esm/object/index.d.ts +0 -1
- package/esm/object/index.d.ts.map +1 -1
- package/esm/object/index.js.map +1 -1
- package/esm/testing/test_type.d.ts +277 -276
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/testing/test_type.js.map +1 -1
- package/esm/tuple/common_prop_keys.d.ts +15 -10
- package/esm/tuple/common_prop_keys.d.ts.map +1 -1
- package/esm/tuple/drop.d.ts +45 -26
- package/esm/tuple/drop.d.ts.map +1 -1
- package/esm/tuple/drop.js.map +1 -1
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts +28 -0
- package/esm/tuple/tuple_plus.common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js +2 -0
- package/esm/tuple/tuple_plus.common_prop_keys.js.map +1 -0
- package/esm/tuple/tuple_plus.d.ts +3 -0
- package/esm/tuple/tuple_plus.d.ts.map +1 -1
- package/esm/tuple/tuple_plus.drop_match.d.ts +6 -0
- package/esm/tuple/tuple_plus.drop_match.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.drop_match.js +2 -0
- package/esm/tuple/tuple_plus.drop_match.js.map +1 -0
- package/esm/tuple/tuple_plus.filter.d.ts +2 -2
- package/esm/tuple/tuple_plus.find.d.ts +64 -0
- package/esm/tuple/tuple_plus.find.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.find.js +2 -0
- package/esm/tuple/tuple_plus.find.js.map +1 -0
- package/esm/tuple/tuple_plus.pad_start.d.ts +7 -6
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/esm/tuple/tuple_type.d.ts +41 -23
- package/esm/tuple/tuple_type.d.ts.map +1 -1
- package/esm/union/union.d.ts +33 -0
- package/esm/union/union.d.ts.map +1 -0
- package/esm/union/union.js +2 -0
- package/esm/union/union.js.map +1 -0
- package/esm/unknown/unknown_type.d.ts +12 -0
- package/esm/unknown/unknown_type.d.ts.map +1 -1
- package/esm/utils/options.d.ts +10 -0
- package/esm/utils/options.d.ts.map +1 -0
- package/esm/utils/options.js +2 -0
- package/esm/utils/options.js.map +1 -0
- package/package.json +1 -1
- package/ts/array/array.entries.ts +4 -2
- package/ts/array/array_plus.common_prop_keys.ts +35 -0
- package/ts/array/array_plus.drop_match.ts +16 -0
- package/ts/array/array_plus.element_match.ts +61 -0
- package/ts/array/array_plus.find.ts +71 -0
- package/ts/array/array_plus.ts +6 -3
- package/ts/array/find_first.ts +71 -0
- package/ts/array/head.ts +28 -6
- package/ts/array/last.ts +26 -6
- package/ts/array/readme.md +128 -28
- package/ts/assertion/assert_type.ts +4 -1
- package/ts/assertion/readme.md +3 -2
- package/ts/index.ts +5 -5
- package/ts/never/never_type.ts +13 -0
- package/ts/object/index.ts +0 -1
- package/ts/testing/test_type.ts +279 -277
- package/ts/tuple/common_prop_keys.ts +18 -32
- package/ts/tuple/drop.ts +61 -60
- package/ts/tuple/readme.md +178 -39
- package/ts/tuple/tuple_plus.common_prop_keys.ts +47 -0
- package/ts/tuple/tuple_plus.drop_match.ts +20 -0
- package/ts/tuple/tuple_plus.filter.ts +2 -2
- package/ts/tuple/tuple_plus.find.ts +88 -0
- package/ts/tuple/tuple_plus.pad_start.ts +28 -25
- package/ts/tuple/tuple_plus.ts +3 -0
- package/ts/tuple/tuple_type.ts +67 -25
- package/ts/union/readme.md +81 -0
- package/ts/union/union.ts +37 -0
- package/ts/unknown/unknown_type.ts +13 -0
- package/ts/utils/options.ts +10 -0
- package/cjs/array/array.find.d.ts +0 -23
- package/cjs/array/array.find.d.ts.map +0 -1
- package/cjs/array/array.find.js.map +0 -1
- package/esm/array/array.find.d.ts +0 -23
- package/esm/array/array.find.d.ts.map +0 -1
- package/esm/array/array.find.js +0 -2
- package/esm/array/array.find.js.map +0 -1
- package/ts/array/array.find.ts +0 -34
package/ts/testing/test_type.ts
CHANGED
|
@@ -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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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`.
|