ts-gems 3.3.0 → 3.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/lib/pick.d.ts CHANGED
@@ -1,75 +1,76 @@
1
1
  import { Or } from './logical.js';
2
2
  import { OmitFunctions } from './omit';
3
- import { IfAny, IfEmptyObject, IfFunction, IfNever, IfUnknown } from './type-check';
3
+ import {
4
+ IfAny,
5
+ IfEmptyObject,
6
+ IfFunction,
7
+ IfNever,
8
+ IfUnknown,
9
+ } from './type-check';
4
10
 
5
11
  /**
6
12
  * From T, pick a set of properties whose keys are in the union K,
7
13
  * while preserving strict type checking.
8
14
  */
9
15
  export type StrictPick<T, X extends keyof T> = {
10
- [K in keyof T as (
11
- Or<
12
- // Omit never keys
13
- IfNever<Exclude<T[K], undefined>>,
14
- // Omit X
15
- K extends X ? false : true
16
- > extends true ? never : K
17
- )]: T[K]
16
+ [K in keyof T as Or<
17
+ // Omit never keys
18
+ IfNever<Exclude<T[K], undefined>>,
19
+ // Omit X
20
+ K extends X ? false : true
21
+ > extends true
22
+ ? never
23
+ : K]: T[K];
18
24
  };
19
25
 
20
26
  /**
21
27
  * Pick all function properties in T
22
28
  */
23
29
  export type PickFunctions<T> = {
24
- [K in keyof T as (
25
- Or<
26
- // Omit never keys
27
- IfNever<Exclude<T[K], undefined>>,
28
- // Omit non functions
29
- IfFunction<Exclude<T[K], undefined>, false, true>
30
- > extends true ? never : K
31
- )]: T[K]
30
+ [K in keyof T as Or<
31
+ // Omit never keys
32
+ IfNever<Exclude<T[K], undefined>>,
33
+ // Omit non functions
34
+ IfFunction<Exclude<T[K], undefined>, false, true>
35
+ > extends true
36
+ ? never
37
+ : K]: T[K];
32
38
  };
33
39
 
34
-
35
40
  /**
36
41
  * Pick all function properties in T
37
42
  */
38
43
  export type PickTypes<T, X> = {
39
- [K in keyof T as (
40
- Or<
41
- // Omit never keys
42
- IfNever<Exclude<T[K], undefined>>,
43
- // Omit types which not exists in X
44
- T[K] extends X ? false :
45
- X extends T[K] ? false : true
46
- > extends true ? never : K
47
- )]: T[K]
44
+ [K in keyof T as Or<
45
+ // Omit never keys
46
+ IfNever<Exclude<T[K], undefined>>,
47
+ // Omit types which not exists in X
48
+ T[K] extends X ? false : X extends T[K] ? false : true
49
+ > extends true
50
+ ? never
51
+ : K]: T[K];
48
52
  };
49
53
 
50
-
51
54
  /**
52
55
  * Pick all function properties in T
53
56
  */
54
57
  export type StrictPickTypes<T, X> = {
55
- [K in keyof T as (
56
- Or<
57
- // Omit never keys
58
- IfNever<Exclude<T[K], undefined>>,
59
- // Omit unknown
60
- IfUnknown<T[K]>,
61
- // Omit any
62
- IfAny<T[K]>,
63
- // Omit {}
64
- IfEmptyObject<T[K]>,
65
- // Omit types which not exists in X
66
- T[K] extends X ? false :
67
- X extends T[K] ? false : true
68
- > extends true ? never : K
69
- )]: T[K]
58
+ [K in keyof T as Or<
59
+ // Omit never keys
60
+ IfNever<Exclude<T[K], undefined>>,
61
+ // Omit unknown
62
+ IfUnknown<T[K]>,
63
+ // Omit any
64
+ IfAny<T[K]>,
65
+ // Omit {}
66
+ IfEmptyObject<T[K]>,
67
+ // Omit types which not exists in X
68
+ T[K] extends X ? false : X extends T[K] ? false : true
69
+ > extends true
70
+ ? never
71
+ : K]: T[K];
70
72
  };
71
73
 
72
-
73
74
  /**
74
75
  * @desc Returns Function keys of an object
75
76
  */
@@ -80,7 +81,6 @@ export type FunctionKeys<T> = keyof PickFunctions<T>;
80
81
  */
81
82
  export type NonFunctionKeys<T> = keyof OmitFunctions<T>;
82
83
 
83
-
84
84
  /**
85
85
  * @desc Returns keys that match given type
86
86
  */
@@ -90,4 +90,3 @@ export type KeysOfTypes<T, X> = keyof PickTypes<T, X>;
90
90
  * @desc Returns keys that equals given type
91
91
  */
92
92
  export type StrictKeysOfTypes<T, X> = keyof StrictPickTypes<T, X>;
93
-
package/lib/readonly.d.ts CHANGED
@@ -5,33 +5,40 @@ import { IfEquals, IfNever } from './type-check';
5
5
  /**
6
6
  * Marks given keys as readonly
7
7
  */
8
- export type ReadonlySome<T, K extends keyof T> = Readonly<Pick<T, K>> & Omit<T, K>;
8
+ export type ReadonlySome<T, K extends keyof T> = Readonly<Pick<T, K>> &
9
+ Omit<T, K>;
9
10
 
10
11
  /**
11
12
  * Make all properties in T readonly deeply
12
13
  */
13
14
  export type DeepReadonly<T> = {
14
- readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
15
- // Do not deep process No-Deep values
16
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
17
- // Deep process objects
18
- : DeepReadonly<Exclude<T[K], undefined>>
15
+ readonly [K in keyof T as IfNever<
16
+ Exclude<T[K], undefined>,
17
+ never,
18
+ K
19
+ >]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
20
+ ? T[K]
21
+ : // Deep process objects
22
+ DeepReadonly<Exclude<T[K], undefined>>;
19
23
  };
20
24
 
21
25
  /**
22
26
  * Make all properties in T readonly deeply
23
27
  */
24
28
  export type DeeperReadonly<T> = {
25
- readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
26
- // Deep process arrays
27
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperReadonly<U>[]
28
- // Do not deep process No-Deep values
29
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
30
- // Deep process objects
31
- : DeeperReadonly<Exclude<T[K], undefined>>
29
+ readonly [K in keyof T as IfNever<
30
+ Exclude<T[K], undefined>,
31
+ never,
32
+ K
33
+ >]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
34
+ ? DeeperReadonly<U>[]
35
+ : // Do not deep process No-Deep values
36
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
37
+ ? T[K]
38
+ : // Deep process objects
39
+ DeeperReadonly<Exclude<T[K], undefined>>;
32
40
  };
33
41
 
34
-
35
42
  /**
36
43
  * Returns readonly keys of an object
37
44
  */
@@ -41,103 +48,100 @@ export type ReadonlyKeys<T> = keyof PickReadonly<T>;
41
48
  * Pick all readonly properties in T
42
49
  */
43
50
  export type PickReadonly<T> = {
44
- [K in keyof T as (
45
- Or<
46
- // Omit never keys
47
- IfNever<Exclude<T[K], undefined>>,
48
- // Omit required
49
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
50
- > extends true ? never : K
51
- )]: T[K]
51
+ [K in keyof T as Or<
52
+ // Omit never keys
53
+ IfNever<Exclude<T[K], undefined>>,
54
+ // Omit required
55
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
56
+ > extends true
57
+ ? never
58
+ : K]: T[K];
52
59
  };
53
60
 
54
61
  /**
55
62
  * Omit all readonly properties in T
56
63
  */
57
64
  export type OmitReadonly<T> = {
58
- [K in keyof T as (
59
- Or<
60
- // Omit never keys
61
- IfNever<Exclude<T[K], undefined>>,
62
- // Omit required
63
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
64
- > extends true ? never : K
65
- )]: T[K]
65
+ [K in keyof T as Or<
66
+ // Omit never keys
67
+ IfNever<Exclude<T[K], undefined>>,
68
+ // Omit required
69
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
70
+ > extends true
71
+ ? never
72
+ : K]: T[K];
66
73
  };
67
74
 
68
-
69
75
  /**
70
76
  * Pick all readonly properties in T deeply
71
77
  */
72
78
  export type DeepPickReadonly<T> = {
73
- [K in keyof T as (
74
- Or<
75
- // Omit never keys
76
- IfNever<Exclude<T[K], undefined>>,
77
- // Omit required
78
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
79
- > extends true ? never : K
80
- )]:
81
- // Do not deep process No-Deep values
82
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
83
- // Deep process objects
84
- : DeepPickReadonly<Exclude<T[K], undefined>>
79
+ [K in keyof T as Or<
80
+ // Omit never keys
81
+ IfNever<Exclude<T[K], undefined>>,
82
+ // Omit required
83
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
84
+ > extends true
85
+ ? never
86
+ : K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
87
+ ? T[K]
88
+ : // Deep process objects
89
+ DeepPickReadonly<Exclude<T[K], undefined>>;
85
90
  };
86
91
 
87
92
  /**
88
93
  * Pick all readonly properties in T deeply
89
94
  */
90
95
  export type DeepOmitReadonly<T> = {
91
- [K in keyof T as (
92
- Or<
93
- // Omit never keys
94
- IfNever<Exclude<T[K], undefined>>,
95
- // Omit required
96
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
97
- > extends true ? never : K
98
- )]:
99
- // Do not deep process No-Deep values
100
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
101
- // Deep process objects
102
- : DeepOmitReadonly<Exclude<T[K], undefined>>
96
+ [K in keyof T as Or<
97
+ // Omit never keys
98
+ IfNever<Exclude<T[K], undefined>>,
99
+ // Omit required
100
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
101
+ > extends true
102
+ ? never
103
+ : K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
104
+ ? T[K]
105
+ : // Deep process objects
106
+ DeepOmitReadonly<Exclude<T[K], undefined>>;
103
107
  };
104
108
 
105
109
  /**
106
110
  * Pick all readonly properties in T deeply including arrays
107
111
  */
108
112
  export type DeeperPickReadonly<T> = {
109
- [K in keyof T as (
110
- Or<
111
- // Omit never keys
112
- IfNever<Exclude<T[K], undefined>>,
113
- // Omit required
114
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
115
- > extends true ? never : K
116
- )]:
117
- // Deep process arrays
118
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperPickReadonly<U>[]
119
- // Do not deep process No-Deep values
120
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
121
- // Deep process objects
122
- : DeeperPickReadonly<Exclude<T[K], undefined>>
113
+ [K in keyof T as Or<
114
+ // Omit never keys
115
+ IfNever<Exclude<T[K], undefined>>,
116
+ // Omit required
117
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
118
+ > extends true
119
+ ? never
120
+ : K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
121
+ ? DeeperPickReadonly<U>[]
122
+ : // Do not deep process No-Deep values
123
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
124
+ ? T[K]
125
+ : // Deep process objects
126
+ DeeperPickReadonly<Exclude<T[K], undefined>>;
123
127
  };
124
128
 
125
129
  /**
126
130
  * Pick all readonly properties in T deeply including arrays
127
131
  */
128
132
  export type DeeperOmitReadonly<T> = {
129
- [K in keyof T as (
130
- Or<
131
- // Omit never keys
132
- IfNever<Exclude<T[K], undefined>>,
133
- // Omit required
134
- IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
135
- > extends true ? never : K
136
- )]:
137
- // Deep process arrays
138
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitReadonly<U>[]
139
- // Do not deep process No-Deep values
140
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
141
- // Deep process objects
142
- : DeeperOmitReadonly<Exclude<T[K], undefined>>
133
+ [K in keyof T as Or<
134
+ // Omit never keys
135
+ IfNever<Exclude<T[K], undefined>>,
136
+ // Omit required
137
+ IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
138
+ > extends true
139
+ ? never
140
+ : K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
141
+ ? DeeperOmitReadonly<U>[]
142
+ : // Do not deep process No-Deep values
143
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
144
+ ? T[K]
145
+ : // Deep process objects
146
+ DeeperOmitReadonly<Exclude<T[K], undefined>>;
143
147
  };
package/lib/required.d.ts CHANGED
@@ -6,31 +6,40 @@ import { IfEquals, IfNever } from './type-check';
6
6
  /**
7
7
  * Marks given keys as required
8
8
  */
9
- export type RequiredSome<T, K extends keyof T> = OmitTypes<Required<Pick<T, K>>, null> & Omit<T, K>;
9
+ export type RequiredSome<T, K extends keyof T> = OmitTypes<
10
+ Required<Pick<T, K>>,
11
+ null
12
+ > &
13
+ Omit<T, K>;
10
14
 
11
15
  /**
12
16
  * Make all properties in T required deeply
13
17
  */
14
18
  export type DeepRequired<T> = {
15
- [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]-?:
16
- // Do not deep process No-Deep values
17
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], undefined>
18
- // Deep process objects
19
- : DeepRequired<Exclude<T[K], undefined>>
19
+ [K in keyof T as IfNever<
20
+ Exclude<T[K], undefined>,
21
+ never,
22
+ K
23
+ >]-?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
24
+ ? Exclude<T[K], undefined>
25
+ : // Deep process objects
26
+ DeepRequired<Exclude<T[K], undefined>>;
20
27
  };
21
28
 
22
-
23
29
  /**
24
30
  * Make all properties in T required deeply including arrays
25
31
  */
26
32
  export type DeeperRequired<T> = {
27
- [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]-?:
28
- // Deep process arrays
29
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperRequired<U>[]
30
- // Do not deep process No-Deep values
31
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], undefined>
32
- // Deep process objects
33
- : DeepRequired<Exclude<T[K], undefined>>
33
+ [K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]-?: Exclude< // Deep process arrays
34
+ T[K],
35
+ undefined
36
+ > extends (infer U)[]
37
+ ? DeeperRequired<U>[]
38
+ : // Do not deep process No-Deep values
39
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
40
+ ? Exclude<T[K], undefined>
41
+ : // Deep process objects
42
+ DeepRequired<Exclude<T[K], undefined>>;
34
43
  };
35
44
 
36
45
  /**
@@ -39,107 +48,104 @@ export type DeeperRequired<T> = {
39
48
  */
40
49
  export type RequiredKeys<T> = keyof PickRequired<T>;
41
50
 
42
-
43
51
  /**
44
52
  * Pick all required properties in T
45
53
  */
46
54
  export type PickRequired<T> = {
47
- [K in keyof T as (
48
- Or<
49
- // Omit never keys
50
- IfNever<Exclude<T[K], undefined>>,
51
- // Omit optional
52
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
53
- > extends true ? never : K
54
- )]: T[K]
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]: T[K];
55
63
  };
56
64
 
57
65
  /**
58
66
  * Pick all required properties in T
59
67
  */
60
68
  export type OmitRequired<T> = {
61
- [K in keyof T as (
62
- Or<
63
- // Omit never keys
64
- IfNever<Exclude<T[K], undefined>>,
65
- // Omit optional
66
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }, false, true>
67
- > extends true ? never : K
68
- )]: T[K]
69
+ [K in keyof T as Or<
70
+ // Omit never keys
71
+ IfNever<Exclude<T[K], undefined>>,
72
+ // Omit optional
73
+ IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }, false, true>
74
+ > extends true
75
+ ? never
76
+ : K]: T[K];
69
77
  };
70
78
 
71
79
  /**
72
80
  * Pick all required properties in T deeply
73
81
  */
74
82
  export type DeepPickRequired<T> = {
75
- [K in keyof T as (
76
- Or<
77
- // Omit never keys
78
- IfNever<Exclude<T[K], undefined>>,
79
- // Omit optional
80
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
81
- > extends true ? never : K
82
- )]:
83
- // Do not deep process No-Deep values
84
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
85
- // Deep process objects
86
- : DeepPickRequired<Exclude<T[K], undefined>>
83
+ [K in keyof T as Or<
84
+ // Omit never keys
85
+ IfNever<Exclude<T[K], undefined>>,
86
+ // Omit optional
87
+ IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
88
+ > extends true
89
+ ? never
90
+ : K]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
91
+ ? T[K]
92
+ : // Deep process objects
93
+ DeepPickRequired<Exclude<T[K], undefined>>;
87
94
  };
88
95
 
89
96
  /**
90
97
  * Omit all required properties in T deeply
91
98
  */
92
99
  export type DeepOmitRequired<T> = {
93
- [K in keyof T as (
94
- Or<
95
- // Omit never keys
96
- IfNever<Exclude<T[K], undefined>>,
97
- // Omit required
98
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
99
- > extends true ? never : K
100
- )]?:
101
- // Do not deep process No-Deep values
102
- IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
103
- // Deep process objects
104
- : DeepOmitRequired<Exclude<T[K], undefined>>
100
+ [K in keyof T as Or<
101
+ // Omit never keys
102
+ IfNever<Exclude<T[K], undefined>>,
103
+ // Omit required
104
+ IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
105
+ > extends true
106
+ ? never
107
+ : K]?: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
108
+ ? T[K]
109
+ : // Deep process objects
110
+ DeepOmitRequired<Exclude<T[K], undefined>>;
105
111
  };
106
112
 
107
113
  /**
108
114
  * Pick all required properties in T deeply including arrays
109
115
  */
110
116
  export type DeeperPickRequired<T> = {
111
- [K in keyof T as (
112
- Or<
113
- // Omit never keys
114
- IfNever<Exclude<T[K], undefined>>,
115
- // Omit required
116
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
117
- > extends true ? never : K
118
- )]:
119
- // Deep process arrays
120
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperPickRequired<U>[]
121
- // Do not deep process No-Deep values
122
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
123
- // Deep process objects
124
- : DeeperPickRequired<Exclude<T[K], undefined>>
117
+ [K in keyof T as Or<
118
+ // Omit never keys
119
+ IfNever<Exclude<T[K], undefined>>,
120
+ // Omit required
121
+ IfEquals<{ [Q in K]: T[K] }, { [Q in K]?: T[K] }>
122
+ > extends true
123
+ ? never
124
+ : K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
125
+ ? DeeperPickRequired<U>[]
126
+ : // Do not deep process No-Deep values
127
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
128
+ ? T[K]
129
+ : // Deep process objects
130
+ DeeperPickRequired<Exclude<T[K], undefined>>;
125
131
  };
126
132
 
127
133
  /**
128
134
  * Omit all required properties in T deeply including arrays
129
135
  */
130
136
  export type DeeperOmitRequired<T> = {
131
- [K in keyof T as (
132
- Or<
133
- // Omit never keys
134
- IfNever<Exclude<T[K], undefined>>,
135
- // Omit required
136
- IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
137
- > extends true ? never : K
138
- )]:
139
- // Deep process arrays
140
- Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitRequired<U>[]
141
- // Do not deep process No-Deep values
142
- : IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
143
- // Deep process objects
144
- : DeeperOmitRequired<Exclude<T[K], undefined>>
137
+ [K in keyof T as Or<
138
+ // Omit never keys
139
+ IfNever<Exclude<T[K], undefined>>,
140
+ // Omit required
141
+ IfEquals<{ [Q in K]: T[K] }, { [Q in K]-?: T[K] }>
142
+ > extends true
143
+ ? never
144
+ : K]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
145
+ ? DeeperOmitRequired<U>[]
146
+ : // Do not deep process No-Deep values
147
+ IfNoDeepValue<Exclude<T[K], undefined>> extends true
148
+ ? T[K]
149
+ : // Deep process objects
150
+ DeeperOmitRequired<Exclude<T[K], undefined>>;
145
151
  };