ts-gems 3.12.0 → 4.0.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.
- 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 +126 -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 +19 -19
- package/lib/non-nullable.d.ts +31 -23
- package/lib/nullish.d.ts +15 -11
- package/lib/omit-never.d.ts +20 -14
- package/lib/omit-undefined.d.ts +14 -10
- package/lib/omit.d.ts +41 -30
- package/lib/partial.d.ts +16 -13
- package/lib/pick.d.ts +46 -38
- package/lib/readonly.d.ts +101 -81
- package/lib/required.d.ts +104 -86
- package/lib/type-check.d.ts +18 -9
- package/package.json +17 -15
package/lib/omit-never.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IfNoDeepValue } from './helpers.js';
|
|
2
|
-
import { IfNever } from './type-check.js';
|
|
2
|
+
import { IfNever, IfTuple } from './type-check.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* OmitNever<T> is a type that omits all properties with a value of type "never".
|
|
@@ -30,25 +30,31 @@ export type OmitNever<T> = {
|
|
|
30
30
|
export type DeepOmitNever<T> = {
|
|
31
31
|
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: IfNoDeepValue<
|
|
32
32
|
// Do not deep process No-Deep values
|
|
33
|
-
|
|
33
|
+
Exclude<T[K], undefined>
|
|
34
34
|
> extends true
|
|
35
35
|
? T[K]
|
|
36
|
-
: // Deep process objects
|
|
37
|
-
DeepOmitNever<
|
|
36
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
37
|
+
DeepOmitNever<Exclude<T[K], undefined>>;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Omit all "never" and "undefined" properties in T deeply including arrays
|
|
42
42
|
*/
|
|
43
43
|
export type DeeperOmitNever<T> = {
|
|
44
|
-
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
DeeperOmitNever<
|
|
44
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: IfTuple<
|
|
45
|
+
NonNullable<T[K]>
|
|
46
|
+
> extends true // Leave fixed-length tuples untouched
|
|
47
|
+
? T[K]
|
|
48
|
+
: NonNullable<
|
|
49
|
+
// Deep process arrays
|
|
50
|
+
T[K]
|
|
51
|
+
> extends readonly (infer U)[]
|
|
52
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
53
|
+
? DeeperOmitNever<U>[] | null
|
|
54
|
+
: DeeperOmitNever<U>[]
|
|
55
|
+
: // Do not deep process No-Deep values
|
|
56
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
57
|
+
? T[K]
|
|
58
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
59
|
+
DeeperOmitNever<Exclude<T[K], undefined>>;
|
|
54
60
|
};
|
package/lib/omit-undefined.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IfNoDeepValue } from './helpers.js';
|
|
2
|
-
import { IfNever } from './type-check.js';
|
|
2
|
+
import { IfNever, IfTuple } from './type-check.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* OmitUndefined<T> is a type that omits all properties with a value of type "undefined".
|
|
@@ -25,13 +25,17 @@ export type DeepOmitUndefined<T> = {
|
|
|
25
25
|
* Omit all "never" and "undefined" properties in T deeply including arrays
|
|
26
26
|
*/
|
|
27
27
|
export type DeeperOmitUndefined<T> = {
|
|
28
|
-
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]:
|
|
29
|
-
T[K]
|
|
30
|
-
> extends
|
|
31
|
-
?
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: IfTuple<
|
|
29
|
+
NonNullable<T[K]>
|
|
30
|
+
> extends true // Leave fixed-length tuples untouched
|
|
31
|
+
? T[K]
|
|
32
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
33
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
34
|
+
? DeeperOmitUndefined<U>[] | null
|
|
35
|
+
: DeeperOmitUndefined<U>[]
|
|
36
|
+
: // Do not deep process No-Deep values
|
|
37
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
38
|
+
? T[K]
|
|
39
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
40
|
+
DeeperOmitUndefined<Exclude<T[K], undefined>>;
|
|
37
41
|
};
|
package/lib/omit.d.ts
CHANGED
|
@@ -1,27 +1,38 @@
|
|
|
1
1
|
import { IfNoDeepValue } from './helpers.js';
|
|
2
2
|
import { Or } from './logical.js';
|
|
3
|
-
import { IfFunction, IfNever } from './type-check.js';
|
|
3
|
+
import { IfFunction, IfNever, IfTuple } from './type-check.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Construct a type with the properties of T except for those in type K,
|
|
7
7
|
* while preserving strict type checking.
|
|
8
8
|
*/
|
|
9
9
|
export type StrictOmit<T, X extends keyof T> = {
|
|
10
|
-
[
|
|
10
|
+
[
|
|
11
|
+
K in keyof T as Or<
|
|
12
|
+
// Omit never keys
|
|
13
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
14
|
+
// Omit X
|
|
15
|
+
K extends X ? true : false
|
|
16
|
+
> extends true
|
|
17
|
+
? never
|
|
18
|
+
: K
|
|
19
|
+
]: T[K];
|
|
11
20
|
};
|
|
12
21
|
|
|
13
22
|
/**
|
|
14
23
|
* Omit all function properties in T
|
|
15
24
|
*/
|
|
16
25
|
export type OmitFunctions<T> = {
|
|
17
|
-
[
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
[
|
|
27
|
+
K in keyof T as Or<
|
|
28
|
+
// Omit never keys
|
|
29
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
30
|
+
// Omit functions
|
|
31
|
+
IfFunction<NonNullable<T[K]>>
|
|
32
|
+
> extends true
|
|
33
|
+
? never
|
|
34
|
+
: K
|
|
35
|
+
]: T[K];
|
|
25
36
|
};
|
|
26
37
|
|
|
27
38
|
/**
|
|
@@ -38,31 +49,31 @@ export type OmitTypes<T, X> = {
|
|
|
38
49
|
* Omit all function properties in T
|
|
39
50
|
*/
|
|
40
51
|
export type DeepOmitTypes<T, X> = {
|
|
41
|
-
[
|
|
42
|
-
Exclude<T[K], undefined | X>,
|
|
43
|
-
|
|
44
|
-
K
|
|
45
|
-
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
52
|
+
[
|
|
53
|
+
K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>
|
|
54
|
+
]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
46
55
|
? Exclude<T[K], X>
|
|
47
|
-
: // Deep process objects
|
|
48
|
-
DeepOmitTypes<
|
|
56
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
57
|
+
DeepOmitTypes<Exclude<T[K], undefined>, X>;
|
|
49
58
|
};
|
|
50
59
|
|
|
51
60
|
/**
|
|
52
61
|
* Omit all function properties in T deeply including arrays
|
|
53
62
|
*/
|
|
54
63
|
export type DeeperOmitTypes<T, X> = {
|
|
55
|
-
[K in keyof T as IfNever<
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
K
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
:
|
|
67
|
-
|
|
64
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>]: IfTuple<
|
|
65
|
+
NonNullable<T[K]>
|
|
66
|
+
> extends true // Leave fixed-length tuples untouched
|
|
67
|
+
? Exclude<T[K], X>
|
|
68
|
+
: NonNullable<
|
|
69
|
+
// Deep process arrays // Do not deep process No-Deep values
|
|
70
|
+
T[K]
|
|
71
|
+
> extends readonly (infer U)[]
|
|
72
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
73
|
+
? DeeperOmitTypes<U, X>[] | null
|
|
74
|
+
: DeeperOmitTypes<U, X>[]
|
|
75
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
76
|
+
? Exclude<T[K], X>
|
|
77
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
78
|
+
DeeperOmitTypes<Exclude<T[K], undefined>, X>;
|
|
68
79
|
};
|
package/lib/partial.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
OmitRequired,
|
|
8
8
|
PickRequired,
|
|
9
9
|
} from './required.js';
|
|
10
|
-
import { IfNever } from './type-check.js';
|
|
10
|
+
import { IfNever, IfTuple } from './type-check.js';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Marks given keys as optional
|
|
@@ -24,24 +24,27 @@ export type DeepPartial<T> = {
|
|
|
24
24
|
Exclude<T[K], undefined>
|
|
25
25
|
> extends true
|
|
26
26
|
? T[K]
|
|
27
|
-
: // Deep process objects
|
|
28
|
-
DeepPartial<
|
|
27
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
28
|
+
DeepPartial<Exclude<T[K], undefined>>;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Partial but deeply including arrays
|
|
33
33
|
*/
|
|
34
34
|
export type DeeperPartial<T> = {
|
|
35
|
-
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
: //
|
|
44
|
-
|
|
35
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: IfTuple<
|
|
36
|
+
NonNullable<T[K]>
|
|
37
|
+
> extends true // Leave fixed-length tuples untouched
|
|
38
|
+
? T[K]
|
|
39
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
40
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
41
|
+
? DeeperPartial<U>[] | null
|
|
42
|
+
: DeeperPartial<U>[]
|
|
43
|
+
: // Do not deep process No-Deep values
|
|
44
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
45
|
+
? T[K]
|
|
46
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
47
|
+
DeeperPartial<Exclude<T[K], undefined>>;
|
|
45
48
|
};
|
|
46
49
|
|
|
47
50
|
/**
|
package/lib/pick.d.ts
CHANGED
|
@@ -13,62 +13,70 @@ import {
|
|
|
13
13
|
* while preserving strict type checking.
|
|
14
14
|
*/
|
|
15
15
|
export type StrictPick<T, X extends keyof T> = {
|
|
16
|
-
[
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
[
|
|
17
|
+
K in keyof T as Or<
|
|
18
|
+
// Omit never keys
|
|
19
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
20
|
+
// Omit X
|
|
21
|
+
K extends X ? false : true
|
|
22
|
+
> extends true
|
|
23
|
+
? never
|
|
24
|
+
: K
|
|
25
|
+
]: T[K];
|
|
24
26
|
};
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
* Pick all function properties in T
|
|
28
30
|
*/
|
|
29
31
|
export type PickFunctions<T> = {
|
|
30
|
-
[
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
[
|
|
33
|
+
K in keyof T as Or<
|
|
34
|
+
// Omit never keys
|
|
35
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
36
|
+
// Omit non functions
|
|
37
|
+
IfFunction<NonNullable<T[K]>, false, true>
|
|
38
|
+
> extends true
|
|
39
|
+
? never
|
|
40
|
+
: K
|
|
41
|
+
]: T[K];
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Pick all function properties in T
|
|
42
46
|
*/
|
|
43
47
|
export type PickTypes<T, X> = {
|
|
44
|
-
[
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
[
|
|
49
|
+
K in keyof T as Or<
|
|
50
|
+
// Omit never keys
|
|
51
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
52
|
+
// Omit types which not exists in X
|
|
53
|
+
T[K] extends X ? false : X extends T[K] ? false : true
|
|
54
|
+
> extends true
|
|
55
|
+
? never
|
|
56
|
+
: K
|
|
57
|
+
]: T[K];
|
|
52
58
|
};
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
61
|
* Pick all function properties in T
|
|
56
62
|
*/
|
|
57
63
|
export type StrictPickTypes<T, X> = {
|
|
58
|
-
[
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
[
|
|
65
|
+
K in keyof T as Or<
|
|
66
|
+
// Omit never keys
|
|
67
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
68
|
+
// Omit unknown
|
|
69
|
+
IfUnknown<T[K]>,
|
|
70
|
+
// Omit any
|
|
71
|
+
IfAny<T[K]>,
|
|
72
|
+
// Omit {}
|
|
73
|
+
IfEmptyObject<T[K]>,
|
|
74
|
+
// Omit types which not exists in X
|
|
75
|
+
T[K] extends X ? false : X extends T[K] ? false : true
|
|
76
|
+
> extends true
|
|
77
|
+
? never
|
|
78
|
+
: K
|
|
79
|
+
]: T[K];
|
|
72
80
|
};
|
|
73
81
|
|
|
74
82
|
/**
|
package/lib/readonly.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IfNoDeepValue } from './helpers.js';
|
|
2
2
|
import { Or } from './logical.js';
|
|
3
|
-
import { IfEquals, IfNever } from './type-check.js';
|
|
3
|
+
import { IfEquals, IfNever, IfTuple } from './type-check.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Marks given keys as readonly
|
|
@@ -12,11 +12,9 @@ export type ReadonlySome<T, K extends keyof T> = Readonly<Pick<T, K>> &
|
|
|
12
12
|
* Make all properties in T readonly deeply
|
|
13
13
|
*/
|
|
14
14
|
export type DeepReadonly<T> = {
|
|
15
|
-
readonly [
|
|
16
|
-
Exclude<T[K], undefined>,
|
|
17
|
-
|
|
18
|
-
K
|
|
19
|
-
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
15
|
+
readonly [
|
|
16
|
+
K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>
|
|
17
|
+
]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
20
18
|
? T[K]
|
|
21
19
|
: // Deep process objects
|
|
22
20
|
DeepReadonly<Exclude<T[K], undefined>>;
|
|
@@ -26,17 +24,19 @@ export type DeepReadonly<T> = {
|
|
|
26
24
|
* Make all properties in T readonly deeply
|
|
27
25
|
*/
|
|
28
26
|
export type DeeperReadonly<T> = {
|
|
29
|
-
readonly [
|
|
30
|
-
Exclude<T[K], undefined>,
|
|
31
|
-
|
|
32
|
-
K
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
readonly [
|
|
28
|
+
K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>
|
|
29
|
+
]: IfTuple<NonNullable<T[K]>> extends true // Leave fixed-length tuples untouched
|
|
30
|
+
? T[K]
|
|
31
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
32
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
33
|
+
? DeeperReadonly<U>[] | null
|
|
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>>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -48,100 +48,120 @@ export type ReadonlyKeys<T> = keyof PickReadonly<T>;
|
|
|
48
48
|
* Pick all readonly properties in T
|
|
49
49
|
*/
|
|
50
50
|
export type PickReadonly<T> = {
|
|
51
|
-
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
[
|
|
52
|
+
K in keyof T as Or<
|
|
53
|
+
// Omit never keys
|
|
54
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
55
|
+
// Omit required
|
|
56
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
|
|
57
|
+
> extends true
|
|
58
|
+
? never
|
|
59
|
+
: K
|
|
60
|
+
]: T[K];
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
64
|
* Omit all readonly properties in T
|
|
63
65
|
*/
|
|
64
66
|
export type OmitReadonly<T> = {
|
|
65
|
-
[
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
[
|
|
68
|
+
K in keyof T as Or<
|
|
69
|
+
// Omit never keys
|
|
70
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
71
|
+
// Omit required
|
|
72
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
|
|
73
|
+
> extends true
|
|
74
|
+
? never
|
|
75
|
+
: K
|
|
76
|
+
]: T[K];
|
|
73
77
|
};
|
|
74
78
|
|
|
75
79
|
/**
|
|
76
80
|
* Pick all readonly properties in T deeply
|
|
77
81
|
*/
|
|
78
82
|
export type DeepPickReadonly<T> = {
|
|
79
|
-
[
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
[
|
|
84
|
+
K in keyof T as Or<
|
|
85
|
+
// Omit never keys
|
|
86
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
87
|
+
// Omit required
|
|
88
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
|
|
89
|
+
> extends true
|
|
90
|
+
? never
|
|
91
|
+
: K
|
|
92
|
+
]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
87
93
|
? T[K]
|
|
88
|
-
: // Deep process objects
|
|
89
|
-
DeepPickReadonly<
|
|
94
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
95
|
+
DeepPickReadonly<Exclude<T[K], undefined>>;
|
|
90
96
|
};
|
|
91
97
|
|
|
92
98
|
/**
|
|
93
99
|
* Pick all readonly properties in T deeply
|
|
94
100
|
*/
|
|
95
101
|
export type DeepOmitReadonly<T> = {
|
|
96
|
-
[
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
[
|
|
103
|
+
K in keyof T as Or<
|
|
104
|
+
// Omit never keys
|
|
105
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
106
|
+
// Omit required
|
|
107
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
|
|
108
|
+
> extends true
|
|
109
|
+
? never
|
|
110
|
+
: K
|
|
111
|
+
]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
104
112
|
? T[K]
|
|
105
|
-
: // Deep process objects
|
|
106
|
-
DeepOmitReadonly<
|
|
113
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
114
|
+
DeepOmitReadonly<Exclude<T[K], undefined>>;
|
|
107
115
|
};
|
|
108
116
|
|
|
109
117
|
/**
|
|
110
118
|
* Pick all readonly properties in T deeply including arrays
|
|
111
119
|
*/
|
|
112
120
|
export type DeeperPickReadonly<T> = {
|
|
113
|
-
[
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
DeeperPickReadonly<
|
|
121
|
+
[
|
|
122
|
+
K in keyof T as Or<
|
|
123
|
+
// Omit never keys
|
|
124
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
125
|
+
// Omit required
|
|
126
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, false, true>
|
|
127
|
+
> extends true
|
|
128
|
+
? never
|
|
129
|
+
: K
|
|
130
|
+
]: IfTuple<NonNullable<T[K]>> extends true // Leave fixed-length tuples untouched
|
|
131
|
+
? T[K]
|
|
132
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
133
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
134
|
+
? DeeperPickReadonly<U>[] | null
|
|
135
|
+
: DeeperPickReadonly<U>[]
|
|
136
|
+
: // Do not deep process No-Deep values
|
|
137
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
138
|
+
? T[K]
|
|
139
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
140
|
+
DeeperPickReadonly<Exclude<T[K], undefined>>;
|
|
127
141
|
};
|
|
128
142
|
|
|
129
143
|
/**
|
|
130
144
|
* Pick all readonly properties in T deeply including arrays
|
|
131
145
|
*/
|
|
132
146
|
export type DeeperOmitReadonly<T> = {
|
|
133
|
-
[
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
DeeperOmitReadonly<
|
|
147
|
+
[
|
|
148
|
+
K in keyof T as Or<
|
|
149
|
+
// Omit never keys
|
|
150
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
151
|
+
// Omit required
|
|
152
|
+
IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }>
|
|
153
|
+
> extends true
|
|
154
|
+
? never
|
|
155
|
+
: K
|
|
156
|
+
]: IfTuple<NonNullable<T[K]>> extends true // Leave fixed-length tuples untouched
|
|
157
|
+
? T[K]
|
|
158
|
+
: NonNullable<T[K]> extends readonly (infer U)[] // Deep process arrays
|
|
159
|
+
? null extends T[K] // Preserve a `| null` member lost by NonNullable above
|
|
160
|
+
? DeeperOmitReadonly<U>[] | null
|
|
161
|
+
: DeeperOmitReadonly<U>[]
|
|
162
|
+
: // Do not deep process No-Deep values
|
|
163
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
164
|
+
? T[K]
|
|
165
|
+
: // Deep process objects (Exclude, not NonNullable - preserves a `| null` member)
|
|
166
|
+
DeeperOmitReadonly<Exclude<T[K], undefined>>;
|
|
147
167
|
};
|