ts-gems 3.3.0 → 3.5.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/combine.d.ts +4 -4
- package/lib/dto.d.ts +11 -7
- package/lib/helpers.d.ts +25 -16
- package/lib/index.cjs +16 -0
- package/lib/index.d.ts +61 -15
- package/lib/index.mjs +16 -0
- package/lib/logical.d.ts +26 -14
- package/lib/mutable.d.ts +23 -18
- package/lib/nullish.d.ts +20 -15
- package/lib/omit-never.d.ts +19 -13
- package/lib/omit.d.ts +31 -20
- package/lib/opaque.ts +1 -1
- package/lib/partial.d.ts +21 -17
- package/lib/pick.d.ts +45 -46
- package/lib/readonly.d.ts +87 -83
- package/lib/required.d.ts +90 -83
- package/lib/type-check.d.ts +110 -70
- package/lib/types.d.ts +41 -20
- package/package.json +41 -27
- package/lib/index.js +0 -0
package/lib/combine.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Merges types without merging types of properties.
|
|
3
3
|
*/
|
|
4
|
-
export type Combine<T1, T2, T3 = {}, T4 = {}> = T1
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export type Combine<T1, T2, T3 = {}, T4 = {}> = T1 &
|
|
5
|
+
Omit<T2, keyof T1> &
|
|
6
|
+
Omit<T3, keyof T1 | keyof T2> &
|
|
7
|
+
Omit<T4, keyof T1 | keyof T2 | keyof T3>;
|
package/lib/dto.d.ts
CHANGED
|
@@ -8,13 +8,17 @@ import { IfNever } from './type-check.js';
|
|
|
8
8
|
* @template T - The type of the data being transferred.
|
|
9
9
|
*/
|
|
10
10
|
export type DTO<T> = {
|
|
11
|
-
[K in keyof T as
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
[K in keyof T as IfNever<
|
|
12
|
+
Exclude<T[K], undefined | Function>,
|
|
13
|
+
never,
|
|
14
|
+
K
|
|
15
|
+
>]: Exclude<T[K], undefined | null> extends (infer U)[] // Deep process arrays
|
|
16
|
+
? DTO<U>[]
|
|
17
|
+
: // Do not deep process No-Deep values
|
|
18
|
+
IfNoDeepValue<Exclude<T[K], undefined | null>> extends true
|
|
19
|
+
? Exclude<T[K], undefined | null>
|
|
20
|
+
: // Deep process objects
|
|
21
|
+
DTO<Exclude<T[K], undefined | null>>;
|
|
18
22
|
};
|
|
19
23
|
|
|
20
24
|
export type PartialDTO<T> = DeepPartial<DTO<T>>;
|
package/lib/helpers.d.ts
CHANGED
|
@@ -4,25 +4,34 @@ import { Builtin } from './types';
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns true if T is excluded from deep operations
|
|
6
6
|
*/
|
|
7
|
-
export type IfNoDeepValue<T> =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
export type IfNoDeepValue<T> = T extends Builtin
|
|
8
|
+
? true
|
|
9
|
+
: IfAny<T> extends true
|
|
10
|
+
? T
|
|
11
|
+
: IfTuple<T> extends true
|
|
12
|
+
? true
|
|
13
|
+
: T extends Function
|
|
14
|
+
? true
|
|
15
|
+
: IfClass<T> extends true
|
|
16
|
+
? true
|
|
17
|
+
: T extends Map<any, any>
|
|
18
|
+
? true
|
|
19
|
+
: T extends ReadonlyMap<any, any>
|
|
20
|
+
? true
|
|
21
|
+
: T extends WeakMap<any, any>
|
|
22
|
+
? true
|
|
23
|
+
: T extends Set<any>
|
|
24
|
+
? true
|
|
25
|
+
: T extends ReadonlySet<any>
|
|
26
|
+
? true
|
|
27
|
+
: T extends WeakSet<any>
|
|
28
|
+
? true
|
|
29
|
+
: T extends any[]
|
|
30
|
+
? true
|
|
31
|
+
: false;
|
|
22
32
|
|
|
23
33
|
/**
|
|
24
34
|
* ValuesOf
|
|
25
35
|
* @desc Returns the union type of all the values in a type
|
|
26
36
|
*/
|
|
27
37
|
export type ValuesOf<T> = T[keyof T];
|
|
28
|
-
|
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const noOp = x => x;
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
asMutable: noOp,
|
|
5
|
+
asDeepMutable: noOp,
|
|
6
|
+
asDeeperMutable: noOp,
|
|
7
|
+
asReadonly: noOp,
|
|
8
|
+
asDeepReadonly: noOp,
|
|
9
|
+
asDeeperReadonly: noOp,
|
|
10
|
+
asPartial: noOp,
|
|
11
|
+
asDeepPartial: noOp,
|
|
12
|
+
asDeeperPartial: noOp,
|
|
13
|
+
asRequired: noOp,
|
|
14
|
+
asDeepRequired: noOp,
|
|
15
|
+
asDeeperRequired: noOp,
|
|
16
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
15
|
-
export * from
|
|
1
|
+
// noinspection JSUnusedGlobalSymbols
|
|
2
|
+
|
|
3
|
+
import { DeeperMutable, DeepMutable, Mutable } from './mutable';
|
|
4
|
+
import { DeeperPartial, DeepPartial } from './partial';
|
|
5
|
+
import { DeeperReadonly, DeepReadonly } from './readonly';
|
|
6
|
+
import { DeeperRequired, DeepRequired } from './required';
|
|
7
|
+
|
|
8
|
+
export * from './combine';
|
|
9
|
+
export * from './dto';
|
|
10
|
+
export * from './helpers';
|
|
11
|
+
export * from './logical';
|
|
12
|
+
export * from './mutable';
|
|
13
|
+
export * from './nullish';
|
|
14
|
+
export * from './omit';
|
|
15
|
+
export * from './omit-never';
|
|
16
|
+
export * from './opaque';
|
|
17
|
+
export * from './partial';
|
|
18
|
+
export * from './pick';
|
|
19
|
+
export * from './readonly';
|
|
20
|
+
export * from './required';
|
|
21
|
+
export * from './type-check';
|
|
22
|
+
export * from './types';
|
|
23
|
+
|
|
24
|
+
declare function asMutable<T>(x: T): Mutable<T>;
|
|
25
|
+
|
|
26
|
+
declare function asDeepMutable<T>(x: T): DeepMutable<T>;
|
|
27
|
+
|
|
28
|
+
declare function asDeeperMutable<T>(x: T): DeeperMutable<T>;
|
|
29
|
+
|
|
30
|
+
declare function asReadonly<T>(x: T): Readonly<T>;
|
|
31
|
+
|
|
32
|
+
declare function asDeepReadonly<T>(x: T): DeepReadonly<T>;
|
|
33
|
+
|
|
34
|
+
declare function asDeeperReadonly<T>(x: T): DeeperReadonly<T>;
|
|
35
|
+
|
|
36
|
+
declare function asPartial<T>(x: T): Partial<T>;
|
|
37
|
+
|
|
38
|
+
declare function asDeepPartial<T>(x: T): DeepPartial<T>;
|
|
39
|
+
|
|
40
|
+
declare function asDeeperPartial<T>(x: T): DeeperPartial<T>;
|
|
41
|
+
|
|
42
|
+
declare function asRequired<T>(x: T): Required<T>;
|
|
43
|
+
|
|
44
|
+
declare function asDeepRequired<T>(x: T): DeepRequired<T>;
|
|
45
|
+
|
|
46
|
+
declare function asDeeperRequired<T>(x: T): DeeperRequired<T>;
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
asDeeperMutable,
|
|
50
|
+
asDeeperPartial,
|
|
51
|
+
asDeeperReadonly,
|
|
52
|
+
asDeeperRequired,
|
|
53
|
+
asDeepMutable,
|
|
54
|
+
asDeepPartial,
|
|
55
|
+
asDeepReadonly,
|
|
56
|
+
asDeepRequired,
|
|
57
|
+
asMutable,
|
|
58
|
+
asPartial,
|
|
59
|
+
asReadonly,
|
|
60
|
+
asRequired,
|
|
61
|
+
};
|
package/lib/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const noOp = x => x;
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
noOp as asDeeperMutable,
|
|
5
|
+
noOp as asDeeperPartial,
|
|
6
|
+
noOp as asDeeperReadonly,
|
|
7
|
+
noOp as asDeeperRequired,
|
|
8
|
+
noOp as asDeepMutable,
|
|
9
|
+
noOp as asDeepPartial,
|
|
10
|
+
noOp as asDeepReadonly,
|
|
11
|
+
noOp as asDeepRequired,
|
|
12
|
+
noOp as asMutable,
|
|
13
|
+
noOp as asPartial,
|
|
14
|
+
noOp as asReadonly,
|
|
15
|
+
noOp as asRequired,
|
|
16
|
+
};
|
package/lib/logical.d.ts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { IfNever } from './type-check';
|
|
2
2
|
|
|
3
3
|
export type And<T1, T2, T3 = true, T4 = true, T5 = true, T6 = true> =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
IfNever<Exclude<T1, undefined | null | false>> extends true
|
|
5
|
+
? false
|
|
6
|
+
: IfNever<Exclude<T2, undefined | null | false>> extends true
|
|
7
|
+
? false
|
|
8
|
+
: IfNever<Exclude<T3, undefined | null | false>> extends true
|
|
9
|
+
? false
|
|
10
|
+
: IfNever<Exclude<T4, undefined | null | false>> extends true
|
|
11
|
+
? false
|
|
12
|
+
: IfNever<Exclude<T5, undefined | null | false>> extends true
|
|
13
|
+
? false
|
|
14
|
+
: IfNever<Exclude<T6, undefined | null | false>> extends true
|
|
15
|
+
? false
|
|
16
|
+
: true;
|
|
11
17
|
|
|
12
18
|
export type Or<T1, T2, T3 = false, T4 = false, T5 = false, T6 = false> =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
IfNever<Exclude<T1, undefined | null | false>> extends false
|
|
20
|
+
? true
|
|
21
|
+
: IfNever<Exclude<T2, undefined | null | false>> extends false
|
|
22
|
+
? true
|
|
23
|
+
: IfNever<Exclude<T3, undefined | null | false>> extends false
|
|
24
|
+
? true
|
|
25
|
+
: IfNever<Exclude<T4, undefined | null | false>> extends false
|
|
26
|
+
? true
|
|
27
|
+
: IfNever<Exclude<T5, undefined | null | false>> extends false
|
|
28
|
+
? true
|
|
29
|
+
: IfNever<Exclude<T6, undefined | null | false>> extends false
|
|
30
|
+
? true
|
|
31
|
+
: false;
|
package/lib/mutable.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
DeepOmitReadonly,
|
|
6
6
|
DeepPickReadonly,
|
|
7
7
|
OmitReadonly,
|
|
8
|
-
PickReadonly
|
|
8
|
+
PickReadonly,
|
|
9
9
|
} from './readonly';
|
|
10
10
|
import { IfNever } from './type-check';
|
|
11
11
|
|
|
@@ -13,38 +13,44 @@ import { IfNever } from './type-check';
|
|
|
13
13
|
* Make all properties in T mutable
|
|
14
14
|
*/
|
|
15
15
|
export type Mutable<T> = {
|
|
16
|
-
-readonly [K in keyof T as
|
|
16
|
+
-readonly [K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: T[K];
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
/**
|
|
21
20
|
* Marks given keys as mutable
|
|
22
21
|
*/
|
|
23
|
-
export type MutableSome<T, K extends keyof T> = Mutable<Pick<T, K>> &
|
|
24
|
-
|
|
22
|
+
export type MutableSome<T, K extends keyof T> = Mutable<Pick<T, K>> &
|
|
23
|
+
Omit<T, K>;
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Make all properties in T mutable deeply
|
|
28
27
|
*/
|
|
29
28
|
export type DeepMutable<T> = {
|
|
30
|
-
-readonly [K in keyof T as
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
-readonly [K in keyof T as IfNever<
|
|
30
|
+
Exclude<T[K], undefined>,
|
|
31
|
+
never,
|
|
32
|
+
K
|
|
33
|
+
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
34
|
+
? T[K]
|
|
35
|
+
: // Deep process objects
|
|
36
|
+
DeepMutable<Exclude<T[K], undefined>>;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* Make all properties in T mutable deeply
|
|
39
41
|
*/
|
|
40
42
|
export type DeeperMutable<T> = {
|
|
41
|
-
-readonly [K in keyof T as
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
-readonly [K in keyof T as IfNever<
|
|
44
|
+
Exclude<T[K], undefined>,
|
|
45
|
+
never,
|
|
46
|
+
K
|
|
47
|
+
>]: Exclude<T[K], undefined> extends (infer U)[] // Deep process arrays
|
|
48
|
+
? DeeperMutable<U>[]
|
|
49
|
+
: // Do not deep process No-Deep values
|
|
50
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
51
|
+
? T[K]
|
|
52
|
+
: // Deep process objects
|
|
53
|
+
DeeperMutable<Exclude<T[K], undefined>>;
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
/**
|
|
@@ -81,4 +87,3 @@ export type DeeperPickMutable<T> = DeeperOmitReadonly<T>;
|
|
|
81
87
|
* Pick all mutable properties in T deeply including arrays
|
|
82
88
|
*/
|
|
83
89
|
export type DeeperOmitMutable<T> = DeeperPickReadonly<T>;
|
|
84
|
-
|
package/lib/nullish.d.ts
CHANGED
|
@@ -4,31 +4,36 @@ import { IfNever } from './type-check';
|
|
|
4
4
|
/**
|
|
5
5
|
* Make all properties in T nullish
|
|
6
6
|
*/
|
|
7
|
-
export type NullishObject<T = null> ={
|
|
8
|
-
[K in keyof T as
|
|
7
|
+
export type NullishObject<T = null> = {
|
|
8
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: T[K] | null;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
/**
|
|
13
12
|
* Make all properties in T nullish deeply
|
|
14
13
|
*/
|
|
15
14
|
export type DeepNullish<T> = {
|
|
16
|
-
[K in keyof T as
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: IfNoDeepValue<
|
|
16
|
+
// Do not deep process No-Deep values
|
|
17
|
+
Exclude<T[K], undefined>
|
|
18
|
+
> extends true
|
|
19
|
+
? T[K] | null
|
|
20
|
+
: // Deep process objects
|
|
21
|
+
DeepNullish<Exclude<T[K], undefined>> | null;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Make all properties in T nullish deeply including arrays
|
|
25
26
|
*/
|
|
26
27
|
export type DeeperNullish<T> = {
|
|
27
|
-
[K in keyof T as
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: Exclude<
|
|
29
|
+
// Deep process arrays
|
|
30
|
+
T[K],
|
|
31
|
+
undefined
|
|
32
|
+
> extends (infer U)[]
|
|
33
|
+
? DeeperNullish<U>[] | null
|
|
34
|
+
: // Do not deep process No-Deep values
|
|
35
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
36
|
+
? T[K] | null
|
|
37
|
+
: // Deep process objects
|
|
38
|
+
DeeperNullish<Exclude<T[K], undefined>> | null;
|
|
34
39
|
};
|
package/lib/omit-never.d.ts
CHANGED
|
@@ -21,29 +21,35 @@ import { IfNever } from './type-check';
|
|
|
21
21
|
* // }
|
|
22
22
|
*/
|
|
23
23
|
export type OmitNever<T> = {
|
|
24
|
-
[K in keyof T as
|
|
24
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: T[K];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Omit all "never" and "undefined" properties in T deeply
|
|
29
29
|
*/
|
|
30
30
|
export type DeepOmitNever<T> = {
|
|
31
|
-
[K in keyof T as
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: IfNoDeepValue<
|
|
32
|
+
// Do not deep process No-Deep values
|
|
33
|
+
Exclude<T[K], undefined>
|
|
34
|
+
> extends true
|
|
35
|
+
? T[K]
|
|
36
|
+
: // Deep process objects
|
|
37
|
+
DeepOmitNever<Exclude<T[K], undefined>>;
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* Omit all "never" and "undefined" properties in T deeply including arrays
|
|
40
42
|
*/
|
|
41
43
|
export type DeeperOmitNever<T> = {
|
|
42
|
-
[K in keyof T as
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]: Exclude<
|
|
45
|
+
// Deep process arrays
|
|
46
|
+
T[K],
|
|
47
|
+
undefined
|
|
48
|
+
> extends (infer U)[]
|
|
49
|
+
? DeeperOmitNever<U>[]
|
|
50
|
+
: // Do not deep process No-Deep values
|
|
51
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
52
|
+
? T[K]
|
|
53
|
+
: // Deep process objects
|
|
54
|
+
DeepOmitNever<Exclude<T[K], undefined>>;
|
|
49
55
|
};
|
package/lib/omit.d.ts
CHANGED
|
@@ -7,48 +7,59 @@ import { IfFunction, IfNever } from './type-check';
|
|
|
7
7
|
* while preserving strict type checking.
|
|
8
8
|
*/
|
|
9
9
|
export type StrictOmit<T, X extends keyof T> = {
|
|
10
|
-
[K in keyof T as
|
|
10
|
+
[K in keyof T as K extends X ? never : K]: T[K];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Omit all function properties in T
|
|
15
15
|
*/
|
|
16
16
|
export type OmitFunctions<T> = {
|
|
17
|
-
[K in keyof T as
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
[K in keyof T as Or<
|
|
18
|
+
// Omit never keys
|
|
19
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
20
|
+
// Omit functions
|
|
21
|
+
IfFunction<Exclude<T[K], undefined>>
|
|
22
|
+
> extends true
|
|
23
|
+
? never
|
|
24
|
+
: K]: T[K];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Exclude from properties of T those types that are assignable to X
|
|
29
29
|
*/
|
|
30
30
|
export type OmitTypes<T, X> = {
|
|
31
|
-
[K in keyof T as
|
|
31
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>]: Exclude<
|
|
32
|
+
T[K],
|
|
33
|
+
X
|
|
34
|
+
>;
|
|
32
35
|
};
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* Omit all function properties in T
|
|
36
39
|
*/
|
|
37
40
|
export type DeepOmitTypes<T, X> = {
|
|
38
|
-
[K in keyof T as
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
[K in keyof T as IfNever<
|
|
42
|
+
Exclude<T[K], undefined | X>,
|
|
43
|
+
never,
|
|
44
|
+
K
|
|
45
|
+
>]: IfNoDeepValue<Exclude<T[K], undefined>> extends true // Do not deep process No-Deep values
|
|
46
|
+
? Exclude<T[K], X>
|
|
47
|
+
: // Deep process objects
|
|
48
|
+
DeepOmitTypes<Exclude<T[K], undefined>, X>;
|
|
42
49
|
};
|
|
43
50
|
|
|
44
51
|
/**
|
|
45
52
|
* Omit all function properties in T deeply including arrays
|
|
46
53
|
*/
|
|
47
54
|
export type DeeperOmitTypes<T, X> = {
|
|
48
|
-
[K in keyof T as
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined | X>, never, K>]: Exclude<
|
|
56
|
+
// Deep process arrays // Do not deep process No-Deep values
|
|
57
|
+
T[K],
|
|
58
|
+
undefined
|
|
59
|
+
> extends (infer U)[]
|
|
60
|
+
? DeeperOmitTypes<U, X>[]
|
|
61
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
62
|
+
? Exclude<T[K], X>
|
|
63
|
+
: // Deep process objects
|
|
64
|
+
DeeperOmitTypes<Exclude<T[K], undefined>, X>;
|
|
54
65
|
};
|
package/lib/opaque.ts
CHANGED
package/lib/partial.d.ts
CHANGED
|
@@ -5,42 +5,46 @@ import {
|
|
|
5
5
|
DeepOmitRequired,
|
|
6
6
|
DeepPickRequired,
|
|
7
7
|
OmitRequired,
|
|
8
|
-
PickRequired
|
|
8
|
+
PickRequired,
|
|
9
9
|
} from './required';
|
|
10
10
|
import { IfNever } from './type-check';
|
|
11
11
|
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Marks given keys as optional
|
|
15
14
|
*/
|
|
16
|
-
export type PartialSome<T, K extends keyof T> = Partial<Pick<T, K>> &
|
|
17
|
-
|
|
15
|
+
export type PartialSome<T, K extends keyof T> = Partial<Pick<T, K>> &
|
|
16
|
+
Omit<T, K>;
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
19
|
* Partial but deeply
|
|
21
20
|
*/
|
|
22
21
|
export type DeepPartial<T> = {
|
|
23
|
-
[K in keyof T as
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: IfNoDeepValue<
|
|
23
|
+
// Do not deep process No-Deep values
|
|
24
|
+
Exclude<T[K], undefined>
|
|
25
|
+
> extends true
|
|
26
|
+
? T[K]
|
|
27
|
+
: // Deep process objects
|
|
28
|
+
DeepPartial<Exclude<T[K], undefined>>;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* Partial but deeply including arrays
|
|
32
33
|
*/
|
|
33
34
|
export type DeeperPartial<T> = {
|
|
34
|
-
[K in keyof T as
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
[K in keyof T as IfNever<Exclude<T[K], undefined>, never, K>]?: Exclude<
|
|
36
|
+
// Deep process arrays
|
|
37
|
+
T[K],
|
|
38
|
+
undefined
|
|
39
|
+
> extends (infer U)[]
|
|
40
|
+
? DeeperPartial<U>[]
|
|
41
|
+
: // Do not deep process No-Deep values
|
|
42
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true
|
|
43
|
+
? T[K]
|
|
44
|
+
: // Deep process objects
|
|
45
|
+
DeeperPartial<Exclude<T[K], undefined>>;
|
|
41
46
|
};
|
|
42
47
|
|
|
43
|
-
|
|
44
48
|
/**
|
|
45
49
|
* OptionalKeys
|
|
46
50
|
* @desc Returns optional keys of an object
|