type-plus 7.3.1 → 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.
- package/README.md +130 -156
- package/cjs/any/any_type.d.ts +8 -8
- package/cjs/any/any_type.d.ts.map +1 -1
- package/cjs/array/array.at.d.ts +3 -1
- package/cjs/array/array.at.d.ts.map +1 -1
- package/cjs/array/array.find.d.ts +3 -1
- package/cjs/array/array.find.d.ts.map +1 -1
- package/cjs/array/array.find_last.d.ts +3 -1
- package/cjs/array/array.find_last.d.ts.map +1 -1
- package/cjs/array/array.some.d.ts +1 -1
- package/cjs/array/array.some.d.ts.map +1 -1
- package/cjs/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/cjs/array/array_plus.concat.d.ts.map +1 -0
- package/cjs/array/{array.concat.js → array_plus.concat.js} +1 -1
- package/cjs/array/array_plus.concat.js.map +1 -0
- package/cjs/array/array_plus.d.ts +3 -2
- package/cjs/array/array_plus.d.ts.map +1 -1
- package/cjs/array/array_plus.filter.d.ts +2 -0
- package/cjs/array/array_plus.filter.d.ts.map +1 -0
- package/cjs/array/array_plus.filter.js +3 -0
- package/cjs/array/array_plus.filter.js.map +1 -0
- package/cjs/array/array_plus.pad_start.d.ts +5 -0
- package/cjs/array/array_plus.pad_start.d.ts.map +1 -0
- package/cjs/array/array_plus.pad_start.js +3 -0
- package/cjs/array/array_plus.pad_start.js.map +1 -0
- package/cjs/array/array_type.d.ts +30 -12
- package/cjs/array/array_type.d.ts.map +1 -1
- package/cjs/array/filter.d.ts +24 -4
- package/cjs/array/filter.d.ts.map +1 -1
- package/cjs/array/head.d.ts +18 -1
- package/cjs/array/head.d.ts.map +1 -1
- package/cjs/array/intersect_of_props.d.ts +5 -3
- package/cjs/array/intersect_of_props.d.ts.map +1 -1
- package/cjs/array/last.d.ts +16 -2
- package/cjs/array/last.d.ts.map +1 -1
- package/cjs/array/literal_array.d.ts +5 -0
- package/cjs/array/literal_array.d.ts.map +1 -1
- package/cjs/array/literal_array.js +5 -0
- package/cjs/array/literal_array.js.map +1 -1
- package/cjs/array/pad_start.d.ts +5 -5
- package/cjs/array/pad_start.d.ts.map +1 -1
- package/cjs/array/reduce_while.d.ts +6 -0
- package/cjs/array/reduce_while.d.ts.map +1 -1
- package/cjs/array/reduce_while.js +6 -0
- package/cjs/array/reduce_while.js.map +1 -1
- package/cjs/array/reverse.d.ts +5 -0
- package/cjs/array/reverse.d.ts.map +1 -1
- package/cjs/array/union_of_props.d.ts +1 -1
- package/cjs/array/union_of_props.d.ts.map +1 -1
- package/cjs/functional/compose.d.ts +2 -1
- package/cjs/functional/compose.d.ts.map +1 -1
- package/cjs/functional/compose.js.map +1 -1
- package/cjs/functional/context.d.ts.map +1 -1
- package/cjs/index.d.ts +19 -3
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +9 -3
- package/cjs/index.js.map +1 -1
- package/cjs/math/numeric_struct.d.ts +1 -1
- package/cjs/math/numeric_struct.d.ts.map +1 -1
- package/cjs/mix_types/any_or_never_type.d.ts +1 -1
- package/cjs/nodejs/isNodeError.d.ts.map +1 -1
- package/cjs/nominal/brand.d.ts.map +1 -1
- package/cjs/nominal/flavor.d.ts.map +1 -1
- package/cjs/testing/test_type.d.ts +44 -1
- package/cjs/testing/test_type.d.ts.map +1 -1
- package/cjs/tuple/common_prop_keys.d.ts +29 -0
- package/cjs/tuple/common_prop_keys.d.ts.map +1 -0
- package/cjs/tuple/common_prop_keys.js.map +1 -0
- package/cjs/tuple/create_tuple.d.ts.map +1 -1
- package/cjs/tuple/drop.d.ts +72 -0
- package/cjs/tuple/drop.d.ts.map +1 -0
- package/cjs/{array → tuple}/drop.js +3 -1
- package/cjs/tuple/drop.js.map +1 -0
- package/{esm/array → cjs/tuple}/tail.d.ts +1 -1
- package/cjs/{array → tuple}/tail.d.ts.map +1 -1
- package/cjs/{array → tuple}/tail.js.map +1 -1
- package/cjs/tuple/tuple_plus.d.ts +2 -1
- package/cjs/tuple/tuple_plus.d.ts.map +1 -1
- package/cjs/tuple/tuple_plus.filter.d.ts +13 -0
- package/cjs/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/cjs/tuple/tuple_plus.filter.js +3 -0
- package/cjs/tuple/tuple_plus.filter.js.map +1 -0
- package/cjs/tuple/tuple_plus.js +0 -15
- package/cjs/tuple/tuple_plus.js.map +1 -1
- package/cjs/tuple/tuple_plus.pad_start.d.ts +8 -3
- package/cjs/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/esm/any/any_type.d.ts +8 -8
- package/esm/any/any_type.d.ts.map +1 -1
- package/esm/array/array.at.d.ts +3 -1
- package/esm/array/array.at.d.ts.map +1 -1
- package/esm/array/array.find.d.ts +3 -1
- package/esm/array/array.find.d.ts.map +1 -1
- package/esm/array/array.find_last.d.ts +3 -1
- package/esm/array/array.find_last.d.ts.map +1 -1
- package/esm/array/array.some.d.ts +1 -1
- package/esm/array/array.some.d.ts.map +1 -1
- package/esm/array/{array.concat.d.ts → array_plus.concat.d.ts} +4 -1
- package/esm/array/array_plus.concat.d.ts.map +1 -0
- package/esm/array/array_plus.concat.js +2 -0
- package/esm/array/array_plus.concat.js.map +1 -0
- package/esm/array/array_plus.d.ts +3 -2
- package/esm/array/array_plus.d.ts.map +1 -1
- package/esm/array/array_plus.filter.d.ts +2 -0
- package/esm/array/array_plus.filter.d.ts.map +1 -0
- package/esm/array/array_plus.filter.js +2 -0
- package/esm/array/array_plus.filter.js.map +1 -0
- package/esm/array/array_plus.pad_start.d.ts +5 -0
- package/esm/array/array_plus.pad_start.d.ts.map +1 -0
- package/esm/array/array_plus.pad_start.js +2 -0
- package/esm/array/array_plus.pad_start.js.map +1 -0
- package/esm/array/array_type.d.ts +30 -12
- package/esm/array/array_type.d.ts.map +1 -1
- package/esm/array/filter.d.ts +24 -4
- package/esm/array/filter.d.ts.map +1 -1
- package/esm/array/head.d.ts +18 -1
- package/esm/array/head.d.ts.map +1 -1
- package/esm/array/intersect_of_props.d.ts +5 -3
- package/esm/array/intersect_of_props.d.ts.map +1 -1
- package/esm/array/last.d.ts +16 -2
- package/esm/array/last.d.ts.map +1 -1
- package/esm/array/literal_array.d.ts +5 -0
- package/esm/array/literal_array.d.ts.map +1 -1
- package/esm/array/literal_array.js +5 -0
- package/esm/array/literal_array.js.map +1 -1
- package/esm/array/pad_start.d.ts +5 -5
- package/esm/array/pad_start.d.ts.map +1 -1
- package/esm/array/reduce_while.d.ts +6 -0
- package/esm/array/reduce_while.d.ts.map +1 -1
- package/esm/array/reduce_while.js +6 -0
- package/esm/array/reduce_while.js.map +1 -1
- package/esm/array/reverse.d.ts +5 -0
- package/esm/array/reverse.d.ts.map +1 -1
- package/esm/array/union_of_props.d.ts +1 -1
- package/esm/array/union_of_props.d.ts.map +1 -1
- package/esm/functional/compose.d.ts +2 -1
- package/esm/functional/compose.d.ts.map +1 -1
- package/esm/functional/compose.js.map +1 -1
- package/esm/functional/context.d.ts.map +1 -1
- package/esm/index.d.ts +19 -3
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -2
- package/esm/index.js.map +1 -1
- package/esm/math/numeric_struct.d.ts +1 -1
- package/esm/math/numeric_struct.d.ts.map +1 -1
- package/esm/mix_types/any_or_never_type.d.ts +1 -1
- package/esm/nodejs/isNodeError.d.ts.map +1 -1
- package/esm/nominal/brand.d.ts.map +1 -1
- package/esm/nominal/flavor.d.ts.map +1 -1
- package/esm/testing/test_type.d.ts +44 -1
- package/esm/testing/test_type.d.ts.map +1 -1
- package/esm/tuple/common_prop_keys.d.ts +29 -0
- package/esm/tuple/common_prop_keys.d.ts.map +1 -0
- package/esm/tuple/common_prop_keys.js.map +1 -0
- package/esm/tuple/create_tuple.d.ts.map +1 -1
- package/esm/tuple/drop.d.ts +72 -0
- package/esm/tuple/drop.d.ts.map +1 -0
- package/esm/tuple/drop.js +9 -0
- package/esm/tuple/drop.js.map +1 -0
- package/{cjs/array → esm/tuple}/tail.d.ts +1 -1
- package/esm/{array → tuple}/tail.d.ts.map +1 -1
- package/esm/{array → tuple}/tail.js.map +1 -1
- package/esm/tuple/tuple_plus.d.ts +2 -1
- package/esm/tuple/tuple_plus.d.ts.map +1 -1
- package/esm/tuple/tuple_plus.filter.d.ts +13 -0
- package/esm/tuple/tuple_plus.filter.d.ts.map +1 -0
- package/esm/tuple/tuple_plus.filter.js +2 -0
- package/esm/tuple/tuple_plus.filter.js.map +1 -0
- package/esm/tuple/tuple_plus.js +1 -1
- package/esm/tuple/tuple_plus.js.map +1 -1
- package/esm/tuple/tuple_plus.pad_start.d.ts +8 -3
- package/esm/tuple/tuple_plus.pad_start.d.ts.map +1 -1
- package/package.json +12 -9
- package/ts/any/any_type.ts +8 -9
- package/ts/any/readme.md +71 -4
- package/ts/array/array.at.ts +3 -1
- package/ts/array/array.find.ts +3 -1
- package/ts/array/array.find_last.ts +3 -1
- package/ts/array/array.some.ts +1 -1
- package/ts/array/{array.concat.ts → array_plus.concat.ts} +3 -0
- package/ts/array/array_plus.filter.ts +5 -0
- package/ts/array/array_plus.pad_start.ts +13 -0
- package/ts/array/array_plus.ts +3 -2
- package/ts/array/array_type.ts +30 -12
- package/ts/array/filter.ts +27 -22
- package/ts/array/head.ts +18 -1
- package/ts/array/intersect_of_props.ts +7 -3
- package/ts/array/last.ts +16 -2
- package/ts/array/literal_array.ts +5 -0
- package/ts/array/pad_start.ts +6 -10
- package/ts/array/readme.md +181 -16
- package/ts/array/reduce_while.ts +6 -0
- package/ts/array/reverse.ts +5 -0
- package/ts/array/union_of_props.ts +1 -1
- package/ts/assertion/readme.md +3 -3
- package/ts/functional/compose.ts +2 -1
- package/ts/functional/context.ts +1 -1
- package/ts/index.ts +22 -3
- package/ts/math/numeric_struct.ts +9 -9
- package/ts/mix_types/any_or_never_type.ts +1 -1
- package/ts/mix_types/readme.md +7 -1
- package/ts/nodejs/isNodeError.ts +13 -13
- package/ts/nominal/brand.ts +1 -1
- package/ts/nominal/flavor.ts +1 -1
- package/ts/testing/readme.md +30 -0
- package/ts/testing/test_type.ts +90 -47
- package/ts/tuple/common_prop_keys.ts +55 -0
- package/ts/tuple/create_tuple.ts +9 -9
- package/ts/tuple/drop.ts +124 -0
- package/ts/tuple/readme.md +116 -1
- package/ts/{array → tuple}/tail.ts +1 -1
- package/ts/tuple/tuple_plus.filter.ts +29 -0
- package/ts/tuple/tuple_plus.pad_start.ts +26 -13
- package/ts/tuple/tuple_plus.ts +2 -1
- package/cjs/array/array.concat.d.ts.map +0 -1
- package/cjs/array/array.concat.js.map +0 -1
- package/cjs/array/common_prop_keys.d.ts +0 -11
- package/cjs/array/common_prop_keys.d.ts.map +0 -1
- package/cjs/array/common_prop_keys.js.map +0 -1
- package/cjs/array/drop.d.ts +0 -19
- package/cjs/array/drop.d.ts.map +0 -1
- package/cjs/array/drop.js.map +0 -1
- package/cjs/array/index.d.ts +0 -17
- package/cjs/array/index.d.ts.map +0 -1
- package/cjs/array/index.js +0 -33
- package/cjs/array/index.js.map +0 -1
- package/esm/array/array.concat.d.ts.map +0 -1
- package/esm/array/array.concat.js +0 -2
- package/esm/array/array.concat.js.map +0 -1
- package/esm/array/common_prop_keys.d.ts +0 -11
- package/esm/array/common_prop_keys.d.ts.map +0 -1
- package/esm/array/common_prop_keys.js.map +0 -1
- package/esm/array/drop.d.ts +0 -19
- package/esm/array/drop.d.ts.map +0 -1
- package/esm/array/drop.js +0 -7
- package/esm/array/drop.js.map +0 -1
- package/esm/array/index.d.ts +0 -17
- package/esm/array/index.d.ts.map +0 -1
- package/esm/array/index.js +0 -17
- package/esm/array/index.js.map +0 -1
- package/ts/array/common_prop_keys.ts +0 -18
- package/ts/array/drop.ts +0 -71
- package/ts/array/index.ts +0 -16
- /package/cjs/{array → tuple}/common_prop_keys.js +0 -0
- /package/cjs/{array → tuple}/tail.js +0 -0
- /package/esm/{array → tuple}/common_prop_keys.js +0 -0
- /package/esm/{array → tuple}/tail.js +0 -0
package/ts/nodejs/isNodeError.ts
CHANGED
|
@@ -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'
|
|
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
|
|
package/ts/nominal/brand.ts
CHANGED
package/ts/nominal/flavor.ts
CHANGED
package/ts/testing/readme.md
CHANGED
|
@@ -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
|
```
|
package/ts/testing/test_type.ts
CHANGED
|
@@ -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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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>
|
package/ts/tuple/create_tuple.ts
CHANGED
|
@@ -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]
|
package/ts/tuple/drop.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { IsEqual } from '../equal/equal.js'
|
|
2
|
+
import type { NonNull, NonUndefined } from '../utils/index.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Drops the first entry in the tuple `T`.
|
|
6
|
+
*
|
|
7
|
+
* If the type is an array, the same array will be returned.
|
|
8
|
+
*
|
|
9
|
+
* ⚗️ *transform*
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type R = DropFirst<[1, 2, 3]> // [2, 3]
|
|
14
|
+
* type R = DropFirst<[string]> // []
|
|
15
|
+
* type R = DropFirst<[]> // []
|
|
16
|
+
* type R = DropFirst<string[]> // string[]
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type DropFirst<T extends unknown[], Cases extends {
|
|
20
|
+
'array'?: unknown,
|
|
21
|
+
'empty_tuple'?: unknown,
|
|
22
|
+
} = {
|
|
23
|
+
'array': T,
|
|
24
|
+
'empty_tuple': [],
|
|
25
|
+
}> = number extends T['length']
|
|
26
|
+
? Cases['array']
|
|
27
|
+
: T['length'] extends 0
|
|
28
|
+
? Cases['empty_tuple']
|
|
29
|
+
: T['length'] extends 1
|
|
30
|
+
? []
|
|
31
|
+
: T extends [any, ...infer Tail]
|
|
32
|
+
? Tail
|
|
33
|
+
: never
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Drops the last entry in the tuple `T`.
|
|
37
|
+
*
|
|
38
|
+
* If the type is an array, the same array will be returned.
|
|
39
|
+
*
|
|
40
|
+
* ⚗️ *transform*
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* type R = DropLast<[1, 2, 3]> // [2, 3]
|
|
45
|
+
* type R = DropLast<[string]> // []
|
|
46
|
+
* type R = DropLast<[]> // []
|
|
47
|
+
* type R = DropLast<string[]> // string[]
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export type DropLast<T extends unknown[], Cases extends {
|
|
51
|
+
'array'?: unknown,
|
|
52
|
+
'empty_tuple'?: unknown,
|
|
53
|
+
} = {
|
|
54
|
+
'array': T,
|
|
55
|
+
'empty_tuple': [],
|
|
56
|
+
}> = number extends T['length']
|
|
57
|
+
? Cases['array']
|
|
58
|
+
: T['length'] extends 0
|
|
59
|
+
? Cases['empty_tuple']
|
|
60
|
+
: T['length'] extends 1
|
|
61
|
+
? []
|
|
62
|
+
: T extends [...infer Heads, any]
|
|
63
|
+
? Heads
|
|
64
|
+
: never
|
|
65
|
+
|
|
66
|
+
type ExcludeUnionOfEmptyTuple<A> = IsEqual<A, []> extends true ? A : Exclude<A, []>
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* drops entries matching `Criteria` in array or tuple `A`.
|
|
70
|
+
*
|
|
71
|
+
* ⚗️ *transform*
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* type R = DropMatch<Array<string | undefined>, undefined> // string[]
|
|
76
|
+
* type R = DropMatch<Array<string>, string> // never[]
|
|
77
|
+
* type R = DropMatch<Array<1 | 2>, number> // never[]
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export type DropMatch<A extends Readonly<Array<unknown>>, Criteria> = number extends A['length']
|
|
81
|
+
? // array
|
|
82
|
+
A[0] extends Criteria
|
|
83
|
+
? // criteria matches: DropAll<string[], string>
|
|
84
|
+
never[]
|
|
85
|
+
: undefined extends Criteria
|
|
86
|
+
? null extends Criteria
|
|
87
|
+
? Array<NonNullable<A[0]>>
|
|
88
|
+
: Array<NonUndefined<A[0]>>
|
|
89
|
+
: null extends Criteria
|
|
90
|
+
? Array<NonNull<A[0]>>
|
|
91
|
+
: Criteria extends A[0]
|
|
92
|
+
? Array<Exclude<A[0], Criteria>>
|
|
93
|
+
: A[0] extends Criteria
|
|
94
|
+
? A
|
|
95
|
+
: Array<Exclude<A[0], Criteria>>
|
|
96
|
+
: DropMatchTuple<A, Criteria>
|
|
97
|
+
|
|
98
|
+
type DropMatchTuple<A extends Readonly<Array<any>>, Criteria> = A['length'] extends 0
|
|
99
|
+
? // empty tuple
|
|
100
|
+
A
|
|
101
|
+
: A extends readonly [infer Head, ...infer Tail]
|
|
102
|
+
? Tail['length'] extends 0
|
|
103
|
+
? // single element tuple
|
|
104
|
+
undefined extends Criteria
|
|
105
|
+
? ExcludeUnionOfEmptyTuple<Head extends Criteria ? [] : [Head]>
|
|
106
|
+
: ExcludeUnionOfEmptyTuple<Head extends Criteria ? [] : [Head]>
|
|
107
|
+
: // multiple elements
|
|
108
|
+
Exclude<Head, Criteria> extends never
|
|
109
|
+
? DropMatch<Tail, Criteria>
|
|
110
|
+
: [Exclude<Head, Criteria>, ...DropMatch<Tail, Criteria>]
|
|
111
|
+
: never[]
|
|
112
|
+
|
|
113
|
+
export type DropNull<A extends Array<any>> = DropMatch<A, null>
|
|
114
|
+
export type DropNullable<A extends Array<any>> = DropMatch<A, null | undefined>
|
|
115
|
+
export type DropUndefined<A extends Array<any>> = DropMatch<A, undefined>
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* drop a particular value from an array.
|
|
119
|
+
*
|
|
120
|
+
* 💀 *deprecated* the type does not sufficiently cover the use cases.
|
|
121
|
+
*/
|
|
122
|
+
export function drop<A extends Readonly<unknown[]>, const C> (array: A, value: C): DropMatch < A, C > {
|
|
123
|
+
return array.filter(v => v !== value) as DropMatch<A, C>
|
|
124
|
+
}
|