ts-gems 2.7.2 → 2.7.3
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/lib/keys.d.ts +35 -29
- package/lib/type-check.d.ts +3 -2
- package/package.json +1 -1
package/lib/keys.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IfEquals, IfCompatible, IfUndefined,
|
|
3
|
+
IfJson, IfNull, IfFunction
|
|
4
|
+
} from './type-check';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* KeyOf
|
|
@@ -17,31 +20,32 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
17
20
|
* @desc Returns required keys of an object
|
|
18
21
|
*/
|
|
19
22
|
export type RequiredKeys<T> = _RequiredKeys<T>
|
|
20
|
-
export type _RequiredKeys<T> = {
|
|
23
|
+
export type _RequiredKeys<T> = ValuesOf<{
|
|
21
24
|
[K in keyof T]-?: IfUndefined<T[K]> extends true ? never
|
|
22
25
|
: T extends { [K1 in K]: any } ? K
|
|
23
26
|
: never
|
|
24
|
-
}
|
|
27
|
+
}>;
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* OptionalKeys
|
|
28
31
|
* @desc Returns optional keys of an object
|
|
29
32
|
*/
|
|
30
33
|
export type OptionalKeys<T> = _OptionalKeys<T>
|
|
31
|
-
export type _OptionalKeys<T> = {
|
|
34
|
+
export type _OptionalKeys<T> = ValuesOf<{
|
|
32
35
|
[K in keyof T]-?: IfUndefined<T[K]> extends true ? never
|
|
33
36
|
: T extends { [K1 in K]: any } ? never
|
|
34
37
|
: K
|
|
35
|
-
}
|
|
38
|
+
}>;
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* @desc Returns readonly keys of an object
|
|
40
43
|
*/
|
|
41
|
-
export type ReadonlyKeys<T> =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
export type ReadonlyKeys<T> = _ReadonlyKeys<T>
|
|
45
|
+
type _ReadonlyKeys<T, J = Required<T>> = ValuesOf<{
|
|
46
|
+
[K in keyof J]: K extends symbol ? never
|
|
47
|
+
: IfEquals<{ [Q in K]: J[K] }, { -readonly [Q in K]: J[K] }, never, K>
|
|
48
|
+
}>;
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* @desc Returns JSON friendly keys of an object
|
|
@@ -58,50 +62,52 @@ type _JsonKeys<T, J = Required<T>> = ValuesOf<{
|
|
|
58
62
|
/**
|
|
59
63
|
* @desc Returns writable keys of an object
|
|
60
64
|
*/
|
|
61
|
-
export type WritableKeys<T> =
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
export type WritableKeys<T> = _WritableKeys<T>;
|
|
66
|
+
type _WritableKeys<T> = ValuesOf<{
|
|
67
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
68
|
+
: IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, never, K>
|
|
69
|
+
}>;
|
|
64
70
|
|
|
65
71
|
|
|
66
72
|
/**
|
|
67
73
|
* @desc Returns writable json keys of an object
|
|
68
74
|
*/
|
|
69
|
-
export type WritableJsonKeys<T> = Extract<
|
|
70
|
-
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, K, never>
|
|
71
|
-
}[keyof T], JsonKeys<T>>;
|
|
75
|
+
export type WritableJsonKeys<T> = Extract<WritableKeys<T>, JsonKeys<T>>;
|
|
72
76
|
|
|
73
77
|
/**
|
|
74
78
|
* @desc Returns Function keys of an object
|
|
75
79
|
*/
|
|
76
|
-
export type FunctionKeys<T> =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
: never : never : never;
|
|
80
|
+
export type FunctionKeys<T> = _FunctionKeys<T>;
|
|
81
|
+
type _FunctionKeys<T> = ValuesOf<{
|
|
82
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
83
|
+
: IfFunction<T[K]> extends true ? K : never;
|
|
81
84
|
}>;
|
|
82
85
|
|
|
83
86
|
/**
|
|
84
87
|
* @desc Returns non function keys of an object
|
|
85
88
|
*/
|
|
86
|
-
export type NonFunctionKeys<T> =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
: K : K : K;
|
|
89
|
+
export type NonFunctionKeys<T> = _NonFunctionKeys<T>;
|
|
90
|
+
type _NonFunctionKeys<T> = ValuesOf<{
|
|
91
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
92
|
+
: IfFunction<T[K]> extends true ? never : K;
|
|
91
93
|
}>;
|
|
92
94
|
|
|
93
95
|
|
|
94
96
|
/**
|
|
95
97
|
* @desc Returns keys that match given type
|
|
96
98
|
*/
|
|
97
|
-
export type KeysCompatible<T, U> =
|
|
98
|
-
|
|
99
|
+
export type KeysCompatible<T, U> = _KeysCompatible<T, U>;
|
|
100
|
+
type _KeysCompatible<T, U> = ValuesOf<{
|
|
101
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
102
|
+
: IfCompatible<T[K], U, K, never>;
|
|
99
103
|
}>;
|
|
100
104
|
|
|
101
105
|
/**
|
|
102
106
|
* @desc Returns keys that equals given type
|
|
103
107
|
*/
|
|
104
|
-
export type KeysEquals<T, U> =
|
|
105
|
-
|
|
108
|
+
export type KeysEquals<T, U> = _KeysEquals<T, U>;
|
|
109
|
+
type _KeysEquals<T, U> = ValuesOf<{
|
|
110
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
111
|
+
: IfEquals<T[K], U, K, never>;
|
|
106
112
|
}>;
|
|
107
113
|
|
package/lib/type-check.d.ts
CHANGED
|
@@ -113,8 +113,9 @@ export type IfFunction<T, Y = true, N = false> =
|
|
|
113
113
|
IfNever<T> extends true ? N
|
|
114
114
|
: IfUndefined<T> extends true ? N
|
|
115
115
|
: IfNull<T> extends true ? N
|
|
116
|
-
: T extends
|
|
117
|
-
:
|
|
116
|
+
: T extends Type ? N
|
|
117
|
+
: T extends Function ? Y
|
|
118
|
+
: N;
|
|
118
119
|
|
|
119
120
|
export type IfFunctionOrAny<T, Y = true, N = false> =
|
|
120
121
|
IfAny<T> extends true ? Y : IfFunction<T, Y, N>;
|