ts-gems 2.7.0 → 2.7.1

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.
@@ -7,7 +7,7 @@ import { IsDeepExcluded } from './helpers.js';
7
7
  export type DeepNullish<T> = _DeepNullish<DeepRequired<T>>;
8
8
  type _DeepNullish<T> =
9
9
  IsDeepExcluded<T> extends true ? T
10
- : { [P in keyof T]: _DeepNullish<Exclude<T[P], undefined>> | null | undefined };
10
+ : { [P in keyof T]?: _DeepNullish<Exclude<T[P], undefined>> | null };
11
11
 
12
12
 
13
13
  /**
@@ -17,5 +17,5 @@ export type HighDeepNullish<T> = _HighDeepNullish<HighDeepRequired<T>>;
17
17
  type _HighDeepNullish<T> =
18
18
  T extends (infer U)[] ? _HighDeepNullish<U>[]
19
19
  : IsDeepExcluded<T> extends true ? T
20
- : { [P in keyof T]: _HighDeepNullish<Exclude<T[P], undefined>> | null | undefined };
20
+ : { [P in keyof T]?: _HighDeepNullish<Exclude<T[P], undefined>> | null };
21
21
 
@@ -4,73 +4,73 @@ import { OptionalKeys, ReadonlyKeys, RequiredKeys, WritableKeys } from './keys';
4
4
  /**
5
5
  * Omit all optional properties in T deeply
6
6
  */
7
- export type DeepOmitOptional<T> = _DeepOmitOptional<T>;
7
+ export type DeepOmitOptional<T> = _DeepOmitOptional<Exclude<T, undefined>>;
8
8
  type _DeepOmitOptional<T, K extends keyof T = Exclude<keyof T, OptionalKeys<T>>> =
9
9
  IsDeepExcluded<T> extends true ? T
10
- : { [P in K]: _DeepOmitOptional<Exclude<T[P], undefined>> };
10
+ : { [P in K]-?: DeepOmitOptional<T[P]> };
11
11
 
12
12
  /**
13
13
  * Omit all optional properties in T deeply including arrays
14
14
  */
15
- export type HighDeepOmitOptional<T> = _HighDeepOmitOptional<T>;
15
+ export type HighDeepOmitOptional<T> = _HighDeepOmitOptional<Exclude<T, undefined>>;
16
16
  type _HighDeepOmitOptional<T, K extends keyof T = Exclude<keyof T, OptionalKeys<T>>> =
17
- T extends (infer U)[] ? _HighDeepOmitOptional<U>[]
17
+ T extends (infer U)[] ? HighDeepOmitOptional<U>[]
18
18
  : IsDeepExcluded<T> extends true ? T
19
- : { [P in K]: _HighDeepOmitOptional<Exclude<T[P], undefined>> };
19
+ : { [P in K]-?: HighDeepOmitOptional<T[P]> };
20
20
 
21
21
 
22
22
  /**
23
23
  * Omit all required properties in T deeply
24
24
  */
25
- export type DeepOmitRequired<T> = _DeepOmitRequired<T>;
25
+ export type DeepOmitRequired<T> = _DeepOmitRequired<Exclude<T, undefined>>;
26
26
  type _DeepOmitRequired<T, J extends keyof T = Exclude<keyof T, RequiredKeys<T>>> =
27
27
  IsDeepExcluded<T> extends true ? T
28
- : { [P in J]: _DeepOmitRequired<Exclude<T[P], undefined>> };
28
+ : { [P in J]?: DeepOmitRequired<Exclude<T[P], undefined>> };
29
29
 
30
30
 
31
31
  /**
32
32
  * Omit all required properties in T deeply including arrays
33
33
  */
34
- export type HighDeepOmitRequired<T> = _HighDeepOmitRequired<T>;
34
+ export type HighDeepOmitRequired<T> = _HighDeepOmitRequired<Exclude<T, undefined>>;
35
35
  type _HighDeepOmitRequired<T, J extends keyof T = Exclude<keyof T, RequiredKeys<T>>> =
36
- T extends (infer U)[] ? _HighDeepOmitRequired<U>[]
36
+ T extends (infer U)[] ? HighDeepOmitRequired<U>[]
37
37
  : IsDeepExcluded<T> extends true ? T
38
- : { [P in J]: _HighDeepOmitRequired<Exclude<T[P], undefined>> };
38
+ : { [P in J]?: HighDeepOmitRequired<Exclude<T[P], undefined>> };
39
39
 
40
40
 
41
41
  /**
42
42
  * Omit all readonly properties in T deeply
43
43
  */
44
- export type DeepOmitReadonly<T> = _DeepOmitReadonly<T>;
44
+ export type DeepOmitReadonly<T> = _DeepOmitReadonly<Exclude<T, undefined>>;
45
45
  type _DeepOmitReadonly<T, J extends keyof T = Exclude<keyof T, ReadonlyKeys<T>>> =
46
46
  IsDeepExcluded<T> extends true ? T
47
- : { [P in J]: _DeepOmitReadonly<Exclude<T[P], undefined>> };
47
+ : { [P in J]: DeepOmitReadonly<T[P]> };
48
48
 
49
49
 
50
50
  /**
51
51
  * Omit all readonly properties in T deeply including arrays
52
52
  */
53
- export type HighDeepOmitReadonly<T> = _HighDeepOmitReadonly<T>;
53
+ export type HighDeepOmitReadonly<T> = _HighDeepOmitReadonly<Exclude<T, undefined>>;
54
54
  type _HighDeepOmitReadonly<T, J extends keyof T = Exclude<keyof T, ReadonlyKeys<T>>> =
55
- T extends (infer U)[] ? _HighDeepOmitReadonly<U>[]
55
+ T extends (infer U)[] ? HighDeepOmitReadonly<U>[]
56
56
  : IsDeepExcluded<T> extends true ? T
57
- : { [P in J]: _HighDeepOmitReadonly<Exclude<T[P], undefined>> };
57
+ : { [P in J]: HighDeepOmitReadonly<T[P]> };
58
58
 
59
59
 
60
60
  /**
61
61
  * Omit all writable properties in T deeply
62
62
  */
63
- export type DeepOmitWritable<T> = _DeepOmitWritable<T>
63
+ export type DeepOmitWritable<T> = _DeepOmitWritable<Exclude<T, undefined>>
64
64
  type _DeepOmitWritable<T, K extends keyof T = Exclude<keyof T, WritableKeys<T>>> =
65
65
  IsDeepExcluded<T> extends true ? T
66
- : { [P in K]: _DeepOmitWritable<Exclude<T[P], undefined>> }
66
+ : { readonly [P in K]: DeepOmitWritable<T[P]> }
67
67
 
68
68
 
69
69
  /**
70
70
  * Omit all writable properties in T deeply including arrays
71
71
  */
72
- export type HighDeepOmitWritable<T> = _HighDeepOmitWritable<T>
72
+ export type HighDeepOmitWritable<T> = _HighDeepOmitWritable<Exclude<T, undefined>>
73
73
  type _HighDeepOmitWritable<T, K extends keyof T = Exclude<keyof T, WritableKeys<T>>> =
74
- T extends (infer U)[] ? _HighDeepOmitWritable<U>[]
74
+ T extends (infer U)[] ? HighDeepOmitWritable<U>[]
75
75
  : IsDeepExcluded<T> extends true ? T
76
- : { [P in K]: _HighDeepOmitWritable<Exclude<T[P], undefined>> }
76
+ : { readonly [P in K]: HighDeepOmitWritable<T[P]> }
@@ -4,81 +4,81 @@ import { JsonKeys, OptionalKeys, ReadonlyKeys, RequiredKeys, WritableKeys } from
4
4
  /**
5
5
  * Pick all optional properties in T deeply
6
6
  */
7
- export type DeepPickOptional<T> = _DeepPickOptional<T>;
7
+ export type DeepPickOptional<T> = _DeepPickOptional<Exclude<T, undefined>>;
8
8
  type _DeepPickOptional<T, K extends keyof T = OptionalKeys<T>> =
9
9
  IsDeepExcluded<T> extends true ? T
10
- : { [P in K]?: _DeepPickOptional<Exclude<T[P], undefined>> };
10
+ : { [P in K]?: DeepPickOptional<T[P]> };
11
11
 
12
12
  /**
13
13
  * Pick all optional properties in T deeply including arrays
14
14
  */
15
- export type HighDeepPickOptional<T> = _HighDeepPickOptional<T>;
15
+ export type HighDeepPickOptional<T> = _HighDeepPickOptional<Exclude<T, undefined>>;
16
16
  type _HighDeepPickOptional<T, K extends keyof T = OptionalKeys<T>> =
17
- T extends (infer U)[] ? _HighDeepPickOptional<U>[]
17
+ T extends (infer U)[] ? HighDeepPickOptional<U>[]
18
18
  : IsDeepExcluded<T> extends true ? T
19
- : { [P in K]?: _HighDeepPickOptional<Exclude<T[P], undefined>> };
19
+ : { [P in K]?: HighDeepPickOptional<T[P]> };
20
20
 
21
21
 
22
22
  /**
23
23
  * Pick all required properties in T deeply
24
24
  */
25
- export type DeepPickRequired<T> = _DeepPickRequired<T>;
25
+ export type DeepPickRequired<T> = _DeepPickRequired<Exclude<T, undefined>>;
26
26
  type _DeepPickRequired<T, J extends keyof T = RequiredKeys<T>> =
27
27
  IsDeepExcluded<T> extends true ? T
28
- : { [P in J]-?: DeepPickRequired<Exclude<T[P], undefined>> };
28
+ : { [P in J]-?: DeepPickRequired<T[P]> };
29
29
 
30
30
 
31
31
  /**
32
32
  * Pick all required properties in T deeply including arrays
33
33
  */
34
- export type HighDeepPickRequired<T> = _HighDeepPickRequired<T>;
34
+ export type HighDeepPickRequired<T> = _HighDeepPickRequired<Exclude<T, undefined>>;
35
35
  type _HighDeepPickRequired<T, J extends keyof T = RequiredKeys<T>> =
36
- T extends (infer U)[] ? _HighDeepPickRequired<U>[]
36
+ T extends (infer U)[] ? HighDeepPickRequired<U>[]
37
37
  : IsDeepExcluded<T> extends true ? T
38
- : { [P in J]-?: _HighDeepPickRequired<Exclude<T[P], undefined>> };
38
+ : { [P in J]-?: HighDeepPickRequired<T[P]> };
39
39
 
40
40
 
41
41
  /**
42
42
  * Pick all readonly properties in T deeply
43
43
  */
44
- export type DeepPickReadonly<T> = _DeepPickReadonly<T>;
44
+ export type DeepPickReadonly<T> = _DeepPickReadonly<Exclude<T, undefined>>;
45
45
  type _DeepPickReadonly<T, K extends keyof T = ReadonlyKeys<T>> =
46
46
  IsDeepExcluded<T> extends true ? T
47
- : { [P in K]: DeepPickReadonly<Exclude<T[P], undefined>> };
47
+ : { [P in K]: DeepPickReadonly<T[P]> };
48
48
 
49
49
  /**
50
50
  * Pick all readonly properties in T deeply including arrays
51
51
  */
52
- export type HighDeepPickReadonly<T> = _HighDeepPickReadonly<T>;
52
+ export type HighDeepPickReadonly<T> = _HighDeepPickReadonly<Exclude<T, undefined>>;
53
53
  type _HighDeepPickReadonly<T, K extends keyof T = ReadonlyKeys<T>> =
54
- T extends (infer U)[] ? _HighDeepPickReadonly<U>[]
54
+ T extends (infer U)[] ? HighDeepPickReadonly<U>[]
55
55
  : IsDeepExcluded<T> extends true ? T
56
- : { [P in K]: _HighDeepPickReadonly<Exclude<T[P], undefined>> };
56
+ : { [P in K]: HighDeepPickReadonly<T[P]> };
57
57
 
58
58
 
59
59
  /**
60
60
  * Pick all writable properties in T deeply
61
61
  */
62
- export type DeepPickWritable<T> = _DeepPickWritable<T>;
62
+ export type DeepPickWritable<T> = _DeepPickWritable<Exclude<T, undefined>>;
63
63
  type _DeepPickWritable<T, K extends keyof T = WritableKeys<T>> =
64
64
  IsDeepExcluded<T> extends true ? T
65
- : { [P in K]: DeepPickWritable<Exclude<T[P], undefined>> };
65
+ : { [P in K]: DeepPickWritable<T[P]> };
66
66
 
67
67
  /**
68
68
  * Pick all writable properties in T deeply including arrays
69
69
  */
70
- export type HighDeepPickWritable<T> = _HighDeepPickWritable<T>;
70
+ export type HighDeepPickWritable<T> = _HighDeepPickWritable<Exclude<T, undefined>>;
71
71
  type _HighDeepPickWritable<T, K extends keyof T = WritableKeys<T>> =
72
- T extends (infer U)[] ? _HighDeepPickWritable<U>[]
72
+ T extends (infer U)[] ? HighDeepPickWritable<U>[]
73
73
  : IsDeepExcluded<T> extends true ? T
74
- : { [P in K]: _HighDeepPickWritable<Exclude<T[P], undefined>> };
74
+ : { [P in K]: HighDeepPickWritable<T[P]> };
75
75
 
76
76
 
77
77
  /**
78
78
  * Pick all JSON friendly properties in T deeply
79
79
  */
80
- export type DeepPickJson<T> = _DeepPickJson<T>
80
+ export type DeepPickJson<T> = _DeepPickJson<Exclude<T, undefined>>;
81
81
  type _DeepPickJson<T, Keys extends keyof T = JsonKeys<T>> =
82
- T extends (infer U)[] ? _DeepPickJson<U>[]
82
+ T extends (infer U)[] ? DeepPickJson<U>[]
83
83
  : IsDeepExcluded<T> extends true ? T
84
- : { [P in Keys]: DeepPickJson<Exclude<T[P], undefined>> };
84
+ : { [P in Keys]: DeepPickJson<T[P]> };
@@ -6,7 +6,7 @@ import { IsDeepExcluded } from './helpers.js';
6
6
  export type DeepReadonly<T> = _DeepReadonly<T>;
7
7
  type _DeepReadonly<T> =
8
8
  IsDeepExcluded<T> extends true ? T
9
- : { readonly [P in keyof T]: _DeepReadonly<Exclude<T[P], undefined>> };
9
+ : { readonly [P in keyof T]: _DeepReadonly<T[P]> };
10
10
 
11
11
  /**
12
12
  * Make all properties in T readonly deeply
@@ -15,5 +15,5 @@ export type HighDeepReadonly<T> = _HighDeepReadonly<T>;
15
15
  type _HighDeepReadonly<T> =
16
16
  T extends (infer U)[] ? _HighDeepReadonly<U>[]
17
17
  : IsDeepExcluded<T> extends true ? T
18
- : { readonly [P in keyof T]: _HighDeepReadonly<Exclude<T[P], undefined>> };
18
+ : { readonly [P in keyof T]: _HighDeepReadonly<T[P]> };
19
19
 
@@ -6,7 +6,7 @@ import { IsDeepExcluded } from './helpers.js';
6
6
  export type DeepWritable<T> = _DeepWritable<T>;
7
7
  type _DeepWritable<T> =
8
8
  IsDeepExcluded<T> extends true ? T
9
- : { -readonly [P in keyof T]: _DeepWritable<Exclude<T[P], undefined>> };
9
+ : { -readonly [P in keyof T]: _DeepWritable<T[P]> };
10
10
 
11
11
 
12
12
  /**
@@ -16,4 +16,4 @@ export type HighDeepWritable<T> = _HighDeepWritable<T>;
16
16
  type _HighDeepWritable<T> =
17
17
  T extends (infer U)[] ? _HighDeepWritable<U>[]
18
18
  : IsDeepExcluded<T> extends true ? T
19
- : { -readonly [P in keyof T]: _HighDeepWritable<Exclude<T[P], undefined>> };
19
+ : { -readonly [P in keyof T]: _HighDeepWritable<T[P]> };
package/lib/keys.d.ts CHANGED
@@ -16,7 +16,8 @@ export type ValuesOf<T> = T[keyof T];
16
16
  * RequiredKeys
17
17
  * @desc Returns required keys of an object
18
18
  */
19
- export type RequiredKeys<T> = {
19
+ export type RequiredKeys<T> = _RequiredKeys<T>
20
+ export type _RequiredKeys<T> = {
20
21
  [K in keyof T]-?: IfUndefined<T[K]> extends true
21
22
  ? never
22
23
  : T extends { [K1 in K]: any } ? K : never
@@ -26,7 +27,8 @@ export type RequiredKeys<T> = {
26
27
  * OptionalKeys
27
28
  * @desc Returns optional keys of an object
28
29
  */
29
- export type OptionalKeys<T> = {
30
+ export type OptionalKeys<T> = _OptionalKeys<T>
31
+ export type _OptionalKeys<T> = {
30
32
  [K in keyof T]-?: IfUndefined<T[K]> extends true
31
33
  ? never
32
34
  : T extends { [K1 in K]: any } ? never : K
@@ -40,11 +42,6 @@ export type ReadonlyKeys<T> = {
40
42
  [K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, never, K>
41
43
  }[keyof T];
42
44
 
43
- /**
44
- * @desc Returns non function keys of an object
45
- */
46
- export type NonFunctionKeys<T> = Exclude<keyof T, FunctionKeys<T>>;
47
-
48
45
 
49
46
  /**
50
47
  * @desc Returns JSON friendly keys of an object
@@ -63,7 +60,9 @@ type _JsonKeys<T, J = Required<T>> = ValuesOf<{
63
60
  /**
64
61
  * @desc Returns writable keys of an object
65
62
  */
66
- export type WritableKeys<T> = Exclude<keyof T, ReadonlyKeys<T>>;
63
+ export type WritableKeys<T> = {
64
+ [K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, never, K>
65
+ }[keyof T];
67
66
 
68
67
 
69
68
  /**
@@ -83,6 +82,18 @@ export type FunctionKeys<T> = ValuesOf<{
83
82
  : never : never : never;
84
83
  }>;
85
84
 
85
+ /**
86
+ * @desc Returns non function keys of an object
87
+ */
88
+ export type NonFunctionKeys<T> = ValuesOf<{
89
+ [K in keyof T]-?: IfUndefined<T[K]> extends false ?
90
+ IfAny<T[K]> extends false ?
91
+ T[K] extends Function ? never
92
+ : K : K : K;
93
+ }>;
94
+
95
+
96
+
86
97
  /**
87
98
  * @desc Returns keys that match given type
88
99
  */
@@ -20,6 +20,11 @@ export type IfNever<T, Y = true, N = false> =
20
20
  export type IfUndefined<T, Y = true, N = false> =
21
21
  IfEquals<T, undefined, Y, N>;
22
22
 
23
+ // export type IfUndefined<T, Y = true, N = false> =
24
+ // IfEquals<T, undefined, Y, N> extends Y ? Y
25
+ // : undefined extends T ? Y : N;
26
+
27
+
23
28
  /**
24
29
  * Returns Y if typeof T is "unknown", N otherwise
25
30
  */
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "lodash",
13
13
  "underscore"
14
14
  ],
15
- "version": "2.7.0",
15
+ "version": "2.7.1",
16
16
  "types": "lib/index.d.ts",
17
17
  "main": "lib/index.js",
18
18
  "module": "lib/index.js",
@@ -23,8 +23,8 @@
23
23
  "compile": "tsc -b tsconfig.json",
24
24
  "lint": "eslint --no-error-on-unmatched-pattern",
25
25
  "test:common": "jest --clearCache && jest --config=./jest.config.js",
26
- "test:strict-null": "jest --clearCache && jest --config=./jest.strict-null.config.js",
27
- "test": "npm run test:common && npm run test:strict-null"
26
+ "test:nostrict": "jest --clearCache && jest --config=./jest.nostrict.config.js",
27
+ "test": "npm run test:common && npm run test:nostrict"
28
28
  },
29
29
  "files": [
30
30
  "LICENSE",