ts-gems 2.9.3 → 3.0.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 +7 -0
- package/lib/helpers.d.ts +11 -4
- package/lib/index.d.ts +13 -14
- package/lib/logical.d.ts +19 -0
- package/lib/mutable.d.ts +84 -0
- package/lib/nullish.d.ts +34 -0
- package/lib/omit-never.d.ts +49 -0
- package/lib/omit.d.ts +37 -48
- package/lib/opaque.ts +12 -0
- package/lib/partial.d.ts +78 -0
- package/lib/pick.d.ts +77 -17
- package/lib/readonly.d.ts +143 -0
- package/lib/required.d.ts +145 -0
- package/lib/type-check.d.ts +20 -38
- package/lib/{common.d.ts → types.d.ts} +14 -45
- package/package.json +1 -1
- package/lib/deep-buildable.d.ts +0 -20
- package/lib/deep-nullish.d.ts +0 -22
- package/lib/deep-omit.d.ts +0 -99
- package/lib/deep-partial.d.ts +0 -19
- package/lib/deep-pick.d.ts +0 -89
- package/lib/deep-readonly.d.ts +0 -21
- package/lib/deep-remove-nulls.d.ts +0 -21
- package/lib/deep-required.d.ts +0 -21
- package/lib/deep-writable.d.ts +0 -21
- package/lib/keys.d.ts +0 -118
- package/lib/modify.d.ts +0 -45
package/lib/combine.d.ts
ADDED
package/lib/helpers.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Builtin } from './common';
|
|
2
1
|
import { IfAny, IfClass, IfTuple } from './type-check';
|
|
2
|
+
import { Builtin } from './types';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns true if T is excluded from deep operations
|
|
6
6
|
*/
|
|
7
|
-
export type IfNoDeepValue<T> =
|
|
8
|
-
type _IfNoDeepValue<T> =
|
|
7
|
+
export type IfNoDeepValue<T> =
|
|
9
8
|
T extends Builtin ? true
|
|
10
9
|
: IfAny<T> extends true ? T
|
|
11
10
|
: IfTuple<T> extends true ? true
|
|
@@ -17,5 +16,13 @@ type _IfNoDeepValue<T> =
|
|
|
17
16
|
: T extends Set<any> ? true
|
|
18
17
|
: T extends ReadonlySet<any> ? true
|
|
19
18
|
: T extends WeakSet<any> ? true
|
|
20
|
-
|
|
19
|
+
: T extends any[] ? true
|
|
21
20
|
: false;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ValuesOf
|
|
25
|
+
* @desc Returns the union type of all the values in a type
|
|
26
|
+
*/
|
|
27
|
+
export type ValuesOf<T> = T[keyof T];
|
|
28
|
+
|
package/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./keys";
|
|
3
|
-
export * from "./type-check";
|
|
4
|
-
export * from "./modify";
|
|
5
|
-
export * from "./deep-buildable";
|
|
6
|
-
export * from "./deep-nullish";
|
|
7
|
-
export * from "./deep-omit";
|
|
8
|
-
export * from "./deep-partial";
|
|
9
|
-
export * from "./deep-pick";
|
|
10
|
-
export * from "./deep-readonly";
|
|
11
|
-
export * from "./deep-remove-nulls";
|
|
12
|
-
export * from "./deep-required";
|
|
13
|
-
export * from "./deep-writable";
|
|
1
|
+
export * from "./combine";
|
|
14
2
|
export * from "./helpers";
|
|
15
|
-
export * from "./
|
|
3
|
+
export * from "./logical.js";
|
|
4
|
+
export * from "./mutable";
|
|
5
|
+
export * from "./nullish";
|
|
16
6
|
export * from "./omit";
|
|
7
|
+
export * from "./omit-never";
|
|
8
|
+
export * from "./opaque";
|
|
9
|
+
export * from "./partial";
|
|
10
|
+
export * from "./pick";
|
|
11
|
+
export * from "./readonly";
|
|
12
|
+
export * from "./required";
|
|
13
|
+
export * from "./type-check";
|
|
14
|
+
export * from "./types";
|
|
15
|
+
|
package/lib/logical.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IfNever } from './type-check';
|
|
2
|
+
|
|
3
|
+
export type And<T1, T2, T3 = true, T4 = true, T5 = true, T6 = true> =
|
|
4
|
+
IfNever<Exclude<T1, undefined | null | false>> extends true ? false :
|
|
5
|
+
IfNever<Exclude<T2, undefined | null | false>> extends true ? false :
|
|
6
|
+
IfNever<Exclude<T3, undefined | null | false>> extends true ? false :
|
|
7
|
+
IfNever<Exclude<T4, undefined | null | false>> extends true ? false :
|
|
8
|
+
IfNever<Exclude<T5, undefined | null | false>> extends true ? false :
|
|
9
|
+
IfNever<Exclude<T6, undefined | null | false>> extends true ? false :
|
|
10
|
+
true;
|
|
11
|
+
|
|
12
|
+
export type Or<T1, T2, T3 = false, T4 = false, T5 = false, T6 = false> =
|
|
13
|
+
IfNever<Exclude<T1, undefined | null | false>> extends false ? true :
|
|
14
|
+
IfNever<Exclude<T2, undefined | null | false>> extends false ? true :
|
|
15
|
+
IfNever<Exclude<T3, undefined | null | false>> extends false ? true :
|
|
16
|
+
IfNever<Exclude<T4, undefined | null | false>> extends false ? true :
|
|
17
|
+
IfNever<Exclude<T5, undefined | null | false>> extends false ? true :
|
|
18
|
+
IfNever<Exclude<T6, undefined | null | false>> extends false ? true :
|
|
19
|
+
false;
|
package/lib/mutable.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { IfNoDeepValue } from './helpers';
|
|
2
|
+
import {
|
|
3
|
+
DeeperOmitReadonly,
|
|
4
|
+
DeeperPickReadonly,
|
|
5
|
+
DeepOmitReadonly,
|
|
6
|
+
DeepPickReadonly,
|
|
7
|
+
OmitReadonly,
|
|
8
|
+
PickReadonly
|
|
9
|
+
} from './readonly';
|
|
10
|
+
import { IfNever } from './type-check';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Make all properties in T mutable
|
|
14
|
+
*/
|
|
15
|
+
export type Mutable<T> = {
|
|
16
|
+
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: T[K];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Marks given keys as mutable
|
|
22
|
+
*/
|
|
23
|
+
export type MutableSome<T, K extends keyof T> = Mutable<Pick<T, K>> & Omit<T, K>;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Make all properties in T mutable deeply
|
|
28
|
+
*/
|
|
29
|
+
export type DeepMutable<T> = {
|
|
30
|
+
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
|
|
31
|
+
// Do not deep process No-Deep values
|
|
32
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
33
|
+
// Deep process objects
|
|
34
|
+
: DeepMutable<Exclude<T[K], undefined>>
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Make all properties in T mutable deeply
|
|
39
|
+
*/
|
|
40
|
+
export type DeeperMutable<T> = {
|
|
41
|
+
-readonly [K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
|
|
42
|
+
// Deep process arrays
|
|
43
|
+
Exclude<T[K], undefined> extends (infer U)[] ? DeeperMutable<U>[]
|
|
44
|
+
// Do not deep process No-Deep values
|
|
45
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
46
|
+
// Deep process objects
|
|
47
|
+
: DeeperMutable<Exclude<T[K], undefined>>
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns mutable keys of an object
|
|
52
|
+
*/
|
|
53
|
+
export type MutableKeys<T> = keyof OmitReadonly<T>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Pick all mutable properties in T
|
|
57
|
+
*/
|
|
58
|
+
export type PickMutable<T> = OmitReadonly<T>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Omit all mutable properties in T
|
|
62
|
+
*/
|
|
63
|
+
export type OmitMutable<T> = PickReadonly<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Pick all mutable properties in T deeply
|
|
67
|
+
*/
|
|
68
|
+
export type DeepPickMutable<T> = DeepOmitReadonly<T>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Pick all mutable properties in T deeply
|
|
72
|
+
*/
|
|
73
|
+
export type DeepOmitMutable<T> = DeepPickReadonly<T>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Pick all mutable properties in T deeply including arrays
|
|
77
|
+
*/
|
|
78
|
+
export type DeeperPickMutable<T> = DeeperOmitReadonly<T>;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Pick all mutable properties in T deeply including arrays
|
|
82
|
+
*/
|
|
83
|
+
export type DeeperOmitMutable<T> = DeeperPickReadonly<T>;
|
|
84
|
+
|
package/lib/nullish.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IfNoDeepValue } from './helpers';
|
|
2
|
+
import { IfNever } from './type-check';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Make all properties in T nullable
|
|
6
|
+
*/
|
|
7
|
+
export type Nullish<T = null> = {
|
|
8
|
+
[P in keyof T]?: T[P] | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Make all properties in T nullable deeply
|
|
14
|
+
*/
|
|
15
|
+
export type DeepNullish<T> = {
|
|
16
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?:
|
|
17
|
+
// Do not deep process No-Deep values
|
|
18
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? (T[K] | null)
|
|
19
|
+
// Deep process objects
|
|
20
|
+
: DeepNullish<Exclude<T[K], undefined>> | null
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Make all properties in T nullable deeply including arrays
|
|
25
|
+
*/
|
|
26
|
+
export type DeeperNullish<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)[] ? DeeperNullish<U>[] | null
|
|
30
|
+
// Do not deep process No-Deep values
|
|
31
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? (T[K] | null)
|
|
32
|
+
// Deep process objects
|
|
33
|
+
: DeeperNullish<Exclude<T[K], undefined>> | null
|
|
34
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IfNoDeepValue } from './helpers';
|
|
2
|
+
import { IfNever } from './type-check';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* OmitNever<T> is a type that omits all properties with a value of type "never".
|
|
6
|
+
*
|
|
7
|
+
* @template T - The original type
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* type MyType = {
|
|
11
|
+
* a: string;
|
|
12
|
+
* b: number;
|
|
13
|
+
* c?: never;
|
|
14
|
+
* };
|
|
15
|
+
*
|
|
16
|
+
* type Result = OmitNever<MyType>;
|
|
17
|
+
* // Result is:
|
|
18
|
+
* // {
|
|
19
|
+
* // a: string;
|
|
20
|
+
* // b: number;
|
|
21
|
+
* // }
|
|
22
|
+
*/
|
|
23
|
+
export type OmitNever<T> = {
|
|
24
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]: T[K]
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Omit all "never" and "undefined" properties in T deeply
|
|
29
|
+
*/
|
|
30
|
+
export type DeepOmitNever<T> = {
|
|
31
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
|
|
32
|
+
// Do not deep process No-Deep values
|
|
33
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
34
|
+
// Deep process objects
|
|
35
|
+
: DeepOmitNever<Exclude<T[K], undefined>>
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Omit all "never" and "undefined" properties in T deeply including arrays
|
|
40
|
+
*/
|
|
41
|
+
export type DeeperOmitNever<T> = {
|
|
42
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]:
|
|
43
|
+
// Deep process arrays
|
|
44
|
+
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitNever<U>[]
|
|
45
|
+
// Do not deep process No-Deep values
|
|
46
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
47
|
+
// Deep process objects
|
|
48
|
+
: DeepOmitNever<Exclude<T[K], undefined>>
|
|
49
|
+
};
|
package/lib/omit.d.ts
CHANGED
|
@@ -1,65 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ReadonlyKeys,
|
|
5
|
-
RequiredKeys,
|
|
6
|
-
WritableKeys
|
|
7
|
-
} from './keys';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* OmitNever<T> is a type that omits all properties with a value of type "never".
|
|
11
|
-
*
|
|
12
|
-
* @template T - The original type
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* type MyType = {
|
|
16
|
-
* a: string;
|
|
17
|
-
* b: number;
|
|
18
|
-
* c?: never;
|
|
19
|
-
* };
|
|
20
|
-
*
|
|
21
|
-
* type Result = OmitNever<MyType>;
|
|
22
|
-
* // Result is:
|
|
23
|
-
* // {
|
|
24
|
-
* // a: string;
|
|
25
|
-
* // b: number;
|
|
26
|
-
* // }
|
|
27
|
-
*/
|
|
28
|
-
export type OmitNever<T> = {
|
|
29
|
-
[K in keyof T as (Exclude<T[K], undefined> extends never ? never : K)]: T[K]
|
|
30
|
-
};
|
|
1
|
+
import { IfNoDeepValue } from './helpers';
|
|
2
|
+
import { Or } from './logical.js';
|
|
3
|
+
import { IfFunction, IfNever } from './type-check';
|
|
31
4
|
|
|
32
5
|
/**
|
|
33
6
|
* Construct a type with the properties of T except for those in type K,
|
|
34
7
|
* while preserving strict type checking.
|
|
35
|
-
*
|
|
36
|
-
* @template T - The original type.
|
|
37
|
-
* @template K - The keys of the properties to be removed from the original type.
|
|
38
|
-
*/
|
|
39
|
-
export type StrictOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Omit all optional properties in T
|
|
43
8
|
*/
|
|
44
|
-
export type
|
|
9
|
+
export type StrictOmit<T, X extends keyof T> = {
|
|
10
|
+
[K in keyof T as (K extends X ? never : K)]: T[K]
|
|
11
|
+
};
|
|
45
12
|
|
|
46
13
|
/**
|
|
47
|
-
* Omit all
|
|
14
|
+
* Omit all function properties in T
|
|
48
15
|
*/
|
|
49
|
-
export type
|
|
16
|
+
export type OmitFunctions<T> = {
|
|
17
|
+
[K in keyof T as (
|
|
18
|
+
Or<
|
|
19
|
+
// Omit never keys
|
|
20
|
+
IfNever<Exclude<T[K], undefined>>,
|
|
21
|
+
// Omit functions
|
|
22
|
+
IfFunction<Exclude<T[K], undefined>>
|
|
23
|
+
> extends true ? never : K
|
|
24
|
+
)]: T[K]
|
|
25
|
+
};
|
|
50
26
|
|
|
51
27
|
/**
|
|
52
|
-
*
|
|
28
|
+
* Exclude from properties of T those types that are assignable to X
|
|
53
29
|
*/
|
|
54
|
-
export type
|
|
55
|
-
|
|
30
|
+
export type OmitTypes<T, X> = {
|
|
31
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: Exclude<T[K], X>
|
|
32
|
+
};
|
|
56
33
|
|
|
57
34
|
/**
|
|
58
|
-
* Omit all
|
|
35
|
+
* Omit all function properties in T
|
|
59
36
|
*/
|
|
60
|
-
export type
|
|
37
|
+
export type DeepOmitTypes<T, X> = {
|
|
38
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: // Do not deep process No-Deep values
|
|
39
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], X>
|
|
40
|
+
// Deep process objects
|
|
41
|
+
: DeepOmitTypes<Exclude<T[K], undefined>, X>
|
|
42
|
+
};
|
|
61
43
|
|
|
62
44
|
/**
|
|
63
|
-
* Omit all
|
|
45
|
+
* Omit all function properties in T deeply including arrays
|
|
64
46
|
*/
|
|
65
|
-
export type
|
|
47
|
+
export type DeeperOmitTypes<T, X> = {
|
|
48
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined | X>, never, K>)]: // Do not deep process No-Deep values
|
|
49
|
+
// Deep process arrays
|
|
50
|
+
Exclude<T[K], undefined> extends (infer U)[] ? DeeperOmitTypes<U, X>[]
|
|
51
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? Exclude<T[K], X>
|
|
52
|
+
// Deep process objects
|
|
53
|
+
: DeeperOmitTypes<Exclude<T[K], undefined>, X>
|
|
54
|
+
};
|
package/lib/opaque.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opaque
|
|
3
|
+
* @desc Create unique type that can't be assigned to base type by accident.
|
|
4
|
+
*/
|
|
5
|
+
declare namespace Symbols {
|
|
6
|
+
export const base: unique symbol;
|
|
7
|
+
export const brand: unique symbol;
|
|
8
|
+
}
|
|
9
|
+
export type Opaque<T, N extends string> = T & {
|
|
10
|
+
readonly [Symbols.base]: N;
|
|
11
|
+
readonly [Symbols.brand]: N;
|
|
12
|
+
}
|
package/lib/partial.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IfNoDeepValue } from './helpers';
|
|
2
|
+
import {
|
|
3
|
+
DeeperOmitRequired,
|
|
4
|
+
DeeperPickRequired,
|
|
5
|
+
DeepOmitRequired,
|
|
6
|
+
DeepPickRequired,
|
|
7
|
+
OmitRequired,
|
|
8
|
+
PickRequired
|
|
9
|
+
} from './required';
|
|
10
|
+
import { IfNever } from './type-check';
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Marks given keys as optional
|
|
15
|
+
*/
|
|
16
|
+
export type PartialSome<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Partial but deeply
|
|
21
|
+
*/
|
|
22
|
+
export type DeepPartial<T> = {
|
|
23
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?:
|
|
24
|
+
// Do not deep process No-Deep values
|
|
25
|
+
IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
26
|
+
// Deep process objects
|
|
27
|
+
: DeepPartial<Exclude<T[K], undefined>>
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Partial but deeply including arrays
|
|
32
|
+
*/
|
|
33
|
+
export type DeeperPartial<T> = {
|
|
34
|
+
[K in keyof T as (IfNever<Exclude<T[K], undefined>, never, K>)]?:
|
|
35
|
+
// Deep process arrays
|
|
36
|
+
Exclude<T[K], undefined> extends (infer U)[] ? DeeperPartial<U>[]
|
|
37
|
+
// Do not deep process No-Deep values
|
|
38
|
+
: IfNoDeepValue<Exclude<T[K], undefined>> extends true ? T[K]
|
|
39
|
+
// Deep process objects
|
|
40
|
+
: DeeperPartial<Exclude<T[K], undefined>>
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* OptionalKeys
|
|
46
|
+
* @desc Returns optional keys of an object
|
|
47
|
+
*/
|
|
48
|
+
export type OptionalKeys<T> = keyof PickOptional<T>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Pick all optional properties in T
|
|
52
|
+
*/
|
|
53
|
+
export type PickOptional<T> = OmitRequired<T>;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Omit all optional properties in T
|
|
57
|
+
*/
|
|
58
|
+
export type OmitOptional<T> = PickRequired<T>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Pick all optional properties in T deeply
|
|
62
|
+
*/
|
|
63
|
+
export type DeepPickOptional<T> = DeepOmitRequired<T>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Omit all optional properties in T deeply
|
|
67
|
+
*/
|
|
68
|
+
export type DeepOmitOptional<T> = DeepPickRequired<T>;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Pick all optional properties in T deeply including arrays
|
|
72
|
+
*/
|
|
73
|
+
export type DeeperPickOptional<T> = DeeperOmitRequired<T>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Omit all optional properties in T deeply including arrays
|
|
77
|
+
*/
|
|
78
|
+
export type DeeperOmitOptional<T> = DeeperPickRequired<T>;
|
package/lib/pick.d.ts
CHANGED
|
@@ -1,33 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ReadonlyKeys,
|
|
5
|
-
RequiredKeys,
|
|
6
|
-
WritableKeys
|
|
7
|
-
} from './keys';
|
|
1
|
+
import { Or } from './logical.js';
|
|
2
|
+
import { OmitFunctions } from './omit';
|
|
3
|
+
import { IfAny, IfEmptyObject, IfFunction, IfNever, IfUnknown } from './type-check';
|
|
8
4
|
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
6
|
+
* From T, pick a set of properties whose keys are in the union K,
|
|
7
|
+
* while preserving strict type checking.
|
|
11
8
|
*/
|
|
12
|
-
export type
|
|
9
|
+
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]
|
|
18
|
+
};
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
|
-
* Pick all
|
|
21
|
+
* Pick all function properties in T
|
|
16
22
|
*/
|
|
17
|
-
export type
|
|
23
|
+
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]
|
|
32
|
+
};
|
|
33
|
+
|
|
18
34
|
|
|
19
35
|
/**
|
|
20
|
-
* Pick all
|
|
36
|
+
* Pick all function properties in T
|
|
21
37
|
*/
|
|
22
|
-
export type
|
|
38
|
+
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]
|
|
48
|
+
};
|
|
23
49
|
|
|
24
50
|
|
|
25
51
|
/**
|
|
26
|
-
* Pick all
|
|
52
|
+
* Pick all function properties in T
|
|
27
53
|
*/
|
|
28
|
-
export type
|
|
54
|
+
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]
|
|
70
|
+
};
|
|
71
|
+
|
|
29
72
|
|
|
30
73
|
/**
|
|
31
|
-
*
|
|
74
|
+
* @desc Returns Function keys of an object
|
|
32
75
|
*/
|
|
33
|
-
export type
|
|
76
|
+
export type FunctionKeys<T> = keyof PickFunctions<T>;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @desc Returns non function keys of an object
|
|
80
|
+
*/
|
|
81
|
+
export type NonFunctionKeys<T> = keyof OmitFunctions<T>;
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @desc Returns keys that match given type
|
|
86
|
+
*/
|
|
87
|
+
export type KeysOfTypes<T, X> = keyof PickTypes<T, X>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @desc Returns keys that equals given type
|
|
91
|
+
*/
|
|
92
|
+
export type StrictKeysOfTypes<T, X> = keyof StrictPickTypes<T, X>;
|
|
93
|
+
|