ts-gems 3.12.0 → 4.0.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 +114 -2
- package/docs/api/combine.md +48 -0
- package/docs/api/dto.md +115 -0
- package/docs/api/helpers.md +97 -0
- package/docs/api/logical.md +48 -0
- package/docs/api/mutable.md +164 -0
- package/docs/api/non-nullable.md +68 -0
- package/docs/api/nullish.md +66 -0
- package/docs/api/omit-never.md +62 -0
- package/docs/api/omit-undefined.md +60 -0
- package/docs/api/omit.md +99 -0
- package/docs/api/opaque.md +56 -0
- package/docs/api/partial.md +135 -0
- package/docs/api/pick.md +115 -0
- package/docs/api/readonly.md +150 -0
- package/docs/api/required.md +146 -0
- package/docs/api/type-check.md +246 -0
- package/docs/api/types.md +238 -0
- package/docs/api.md +113 -0
- package/docs/logo.svg +43 -0
- package/lib/dto.d.ts +14 -12
- package/lib/helpers.d.ts +16 -15
- package/lib/mutable.d.ts +15 -17
- package/lib/non-nullable.d.ts +31 -23
- package/lib/nullish.d.ts +15 -11
- package/lib/omit-never.d.ts +15 -11
- package/lib/omit-undefined.d.ts +12 -10
- package/lib/omit.d.ts +37 -28
- package/lib/partial.d.ts +12 -11
- package/lib/pick.d.ts +46 -38
- package/lib/readonly.d.ts +91 -77
- package/lib/required.d.ts +91 -75
- package/lib/type-check.d.ts +10 -9
- package/package.json +17 -15
package/lib/required.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IfNoDeepValue } from './helpers.js';
|
|
2
2
|
import { Or } from './logical.js';
|
|
3
3
|
import { OmitTypes } from './omit.js';
|
|
4
|
-
import { IfEquals, IfNever } from './type-check.js';
|
|
4
|
+
import { IfEquals, IfNever, IfTuple } from './type-check.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Marks given keys as required
|
|
@@ -16,11 +16,9 @@ export type RequiredSome<T, K extends keyof T> = OmitTypes<
|
|
|
16
16
|
* Make all properties in T required deeply
|
|
17
17
|
*/
|
|
18
18
|
export type DeepRequired<T> = {
|
|
19
|
-
[
|
|
20
|
-
Exclude<T[K], undefined>,
|
|
21
|
-
|
|
22
|
-
K
|
|
23
|
-
>]-?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
19
|
+
[
|
|
20
|
+
K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>
|
|
21
|
+
]-?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
24
22
|
? Exclude<T[K], undefined>
|
|
25
23
|
: // Deep process objects
|
|
26
24
|
DeepRequired<NonNullable<T[K]>>;
|
|
@@ -30,15 +28,17 @@ export type DeepRequired<T> = {
|
|
|
30
28
|
* Make all properties in T required deeply including arrays
|
|
31
29
|
*/
|
|
32
30
|
export type DeeperRequired<T> = {
|
|
33
|
-
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]-?:
|
|
34
|
-
T[K]
|
|
35
|
-
> extends
|
|
36
|
-
?
|
|
37
|
-
:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
31
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]-?: IfTuple<
|
|
32
|
+
NonNullable<T[K]>
|
|
33
|
+
> extends true // Leave fixed-length tuples untouched
|
|
34
|
+
? Exclude<T[K], undefined>
|
|
35
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
36
|
+
? DeeperRequired<U>[]
|
|
37
|
+
: // Do not deep process No-Deep values
|
|
38
|
+
IfNoDeepValue<NonNullable<T[K]>> extends true
|
|
39
|
+
? Exclude<T[K], undefined>
|
|
40
|
+
: // Deep process objects
|
|
41
|
+
DeeperRequired<NonNullable<T[K]>>;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/**
|
|
@@ -51,42 +51,48 @@ export type RequiredKeys<T> = keyof PickRequired<T>;
|
|
|
51
51
|
* Pick all required properties in T
|
|
52
52
|
*/
|
|
53
53
|
export type PickRequired<T> = {
|
|
54
|
-
[
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
[
|
|
55
|
+
K in keyof T as Or<
|
|
56
|
+
// Omit never keys
|
|
57
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
58
|
+
// Omit optional
|
|
59
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
|
|
60
|
+
> extends true
|
|
61
|
+
? never
|
|
62
|
+
: K
|
|
63
|
+
]: T[K];
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
* Pick all required properties in T
|
|
66
68
|
*/
|
|
67
69
|
export type OmitRequired<T> = {
|
|
68
|
-
[
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
[
|
|
71
|
+
K in keyof T as Or<
|
|
72
|
+
// Omit never keys
|
|
73
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
74
|
+
// Omit optional
|
|
75
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }, false, true>
|
|
76
|
+
> extends true
|
|
77
|
+
? never
|
|
78
|
+
: K
|
|
79
|
+
]: T[K];
|
|
76
80
|
};
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
* Pick all required properties in T deeply
|
|
80
84
|
*/
|
|
81
85
|
export type DeepPickRequired<T> = {
|
|
82
|
-
[
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
[
|
|
87
|
+
K in keyof T as Or<
|
|
88
|
+
// Omit never keys
|
|
89
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
90
|
+
// Omit optional
|
|
91
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
|
|
92
|
+
> extends true
|
|
93
|
+
? never
|
|
94
|
+
: K
|
|
95
|
+
]: IfNoDeepValue<NonNullable<T[K]>> extends true // Do not deep process No-Deep values
|
|
90
96
|
? T[K]
|
|
91
97
|
: // Deep process objects
|
|
92
98
|
DeepPickRequired<NonNullable<T[K]>>;
|
|
@@ -96,14 +102,16 @@ export type DeepPickRequired<T> = {
|
|
|
96
102
|
* Omit all required properties in T deeply
|
|
97
103
|
*/
|
|
98
104
|
export type DeepOmitRequired<T> = {
|
|
99
|
-
[
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
[
|
|
106
|
+
K in keyof T as Or<
|
|
107
|
+
// Omit never keys
|
|
108
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
109
|
+
// Omit required
|
|
110
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
|
|
111
|
+
> extends true
|
|
112
|
+
? never
|
|
113
|
+
: K
|
|
114
|
+
]?: IfNoDeepValue<NonNullable<T[K]>> extends true // Do not deep process No-Deep values
|
|
107
115
|
? T[K]
|
|
108
116
|
: // Deep process objects
|
|
109
117
|
DeepOmitRequired<NonNullable<T[K]>>;
|
|
@@ -113,38 +121,46 @@ export type DeepOmitRequired<T> = {
|
|
|
113
121
|
* Pick all required properties in T deeply including arrays
|
|
114
122
|
*/
|
|
115
123
|
export type DeeperPickRequired<T> = {
|
|
116
|
-
[
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
[
|
|
125
|
+
K in keyof T as Or<
|
|
126
|
+
// Omit never keys
|
|
127
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
128
|
+
// Omit required
|
|
129
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
|
|
130
|
+
> extends true
|
|
131
|
+
? never
|
|
132
|
+
: K
|
|
133
|
+
]: IfTuple<NonNullable<T[K]>> extends true // Leave fixed-length tuples untouched
|
|
134
|
+
? T[K]
|
|
135
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
136
|
+
? DeeperPickRequired<U>[]
|
|
137
|
+
: // Do not deep process No-Deep values
|
|
138
|
+
IfNoDeepValue<NonNullable<T[K]>> extends true
|
|
139
|
+
? T[K]
|
|
140
|
+
: // Deep process objects
|
|
141
|
+
DeeperPickRequired<NonNullable<T[K]>>;
|
|
130
142
|
};
|
|
131
143
|
|
|
132
144
|
/**
|
|
133
145
|
* Omit all required properties in T deeply including arrays
|
|
134
146
|
*/
|
|
135
147
|
export type DeeperOmitRequired<T> = {
|
|
136
|
-
[
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
[
|
|
149
|
+
K in keyof T as Or<
|
|
150
|
+
// Omit never keys
|
|
151
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
152
|
+
// Omit required
|
|
153
|
+
IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
|
|
154
|
+
> extends true
|
|
155
|
+
? never
|
|
156
|
+
: K
|
|
157
|
+
]: IfTuple<NonNullable<T[K]>> extends true // Leave fixed-length tuples untouched
|
|
158
|
+
? T[K]
|
|
159
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
160
|
+
? DeeperOmitRequired<U>[]
|
|
161
|
+
: // Do not deep process No-Deep values
|
|
162
|
+
IfNoDeepValue<NonNullable<T[K]>> extends true
|
|
163
|
+
? T[K]
|
|
164
|
+
: // Deep process objects
|
|
165
|
+
DeeperOmitRequired<NonNullable<T[K]>>;
|
|
150
166
|
};
|
package/lib/type-check.d.ts
CHANGED
|
@@ -48,13 +48,15 @@ export type IfNullish<T, Y = true, N = false> =
|
|
|
48
48
|
* Returns Y if typeof T is a tuple, N otherwise
|
|
49
49
|
*/
|
|
50
50
|
export type IfTuple<T, Y = true, N = false> =
|
|
51
|
-
|
|
52
|
-
?
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
IfAny<T> extends true
|
|
52
|
+
? N
|
|
53
|
+
: IfNever<T> extends true
|
|
54
|
+
? N
|
|
55
|
+
: T extends readonly unknown[]
|
|
56
|
+
? number extends T['length']
|
|
57
|
+
? N
|
|
58
|
+
: Y
|
|
59
|
+
: N;
|
|
58
60
|
export type IfTupleOrAny<T, Y = true, N = false> =
|
|
59
61
|
IfAny<T> extends true ? Y : IfTuple<T, Y, N>;
|
|
60
62
|
|
|
@@ -127,8 +129,7 @@ export type IfClassOrAny<T, Y = true, N = false> =
|
|
|
127
129
|
* Returns "Y" if "T1" is exactly same with "T2", "N" otherwise
|
|
128
130
|
*/
|
|
129
131
|
export type IfEquals<T1, T2, Y = true, N = false> =
|
|
130
|
-
| IfObject<
|
|
131
|
-
| IfObject<T2> extends true
|
|
132
|
+
IfObject<T1> | IfObject<T2> extends true
|
|
132
133
|
? (<G>() => G extends EqualsWrapped<T1> ? 1 : 2) extends <
|
|
133
134
|
G,
|
|
134
135
|
>() => G extends EqualsWrapped<T2> ? 1 : 2
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-gems",
|
|
3
3
|
"description": "Valuable typing extensions for TypeScript",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"module": "./lib/index.js",
|
|
@@ -17,29 +17,31 @@
|
|
|
17
17
|
"lint": "eslint . --max-warnings=0",
|
|
18
18
|
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
19
19
|
"format": "prettier . --write --log-level=warn",
|
|
20
|
-
"test": "npm run test:common && npm run test:nostrict",
|
|
20
|
+
"test": "tsc -b tsconfig.json && npm run test:common && npm run test:nostrict",
|
|
21
21
|
"test:common": "mocha",
|
|
22
|
-
"test:nostrict": "TS_NODE_PROJECT=\"tsconfig.json\" && mocha"
|
|
22
|
+
"test:nostrict": "TS_NODE_PROJECT=\"tsconfig.json\" && mocha",
|
|
23
|
+
"graph": "graphify upate ."
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@panates/eslint-config": "^2.1.
|
|
26
|
-
"@panates/eslint-config-ts": "^2.1.
|
|
27
|
-
"@panates/tsconfig": "^2.1.
|
|
28
|
-
"@swc/core": "^1.
|
|
29
|
-
"@swc/helpers": "^0.5.
|
|
30
|
-
"@swc-node/register": "^1.
|
|
26
|
+
"@panates/eslint-config": "^2.1.6",
|
|
27
|
+
"@panates/eslint-config-ts": "^2.1.6",
|
|
28
|
+
"@panates/tsconfig": "^2.1.6",
|
|
29
|
+
"@swc/core": "^1.16.2",
|
|
30
|
+
"@swc/helpers": "^0.5.23",
|
|
31
|
+
"@swc-node/register": "^1.12.1",
|
|
31
32
|
"@types/mocha": "^10.0.10",
|
|
32
|
-
"@types/node": "^
|
|
33
|
-
"c8": "^
|
|
34
|
-
"globals": "^17.
|
|
33
|
+
"@types/node": "^26.5.0",
|
|
34
|
+
"c8": "^12.0.0",
|
|
35
|
+
"globals": "^17.12.0",
|
|
35
36
|
"husky": "^9.1.7",
|
|
36
|
-
"mocha": "^
|
|
37
|
-
"prettier": "^3.
|
|
38
|
-
"typescript": "
|
|
37
|
+
"mocha": "^12.0.0",
|
|
38
|
+
"prettier": "^3.9.6",
|
|
39
|
+
"typescript": "6.0.3"
|
|
39
40
|
},
|
|
40
41
|
"files": [
|
|
41
42
|
"LICENSE",
|
|
42
43
|
"README",
|
|
44
|
+
"docs/",
|
|
43
45
|
"lib/"
|
|
44
46
|
],
|
|
45
47
|
"keywords": [
|