-
Notifications
You must be signed in to change notification settings - Fork 1
/
DeepReadOnly.ts
107 lines (107 loc) · 3.35 KB
/
DeepReadOnly.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
export declare type SetIntersection<A, B> = A extends B ? A : never;
export declare type SetDifference<A, B> = A extends B ? never : A;
export declare type SetComplement<A, A1 extends A> = SetDifference<A, A1>;
export declare type SymmetricDifference<A, B> = SetDifference<A | B, A & B>;
export declare type NonUndefined<A> = A extends undefined ? never : A;
export declare type FunctionKeys<T extends object> = {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
export declare type NonFunctionKeys<T extends object> = {
[K in keyof T]: T[K] extends Function ? never : K;
}[keyof T];
export declare type Omit<T extends object, K extends keyof T> = T extends any
? Pick<T, SetDifference<keyof T, K>>
: never;
export declare type PickByValue<T, ValueType> = Pick<
T,
{
[Key in keyof T]: T[Key] extends ValueType ? Key : never;
}[keyof T]
>;
export declare type OmitByValue<T, ValueType> = Pick<
T,
{
[Key in keyof T]: T[Key] extends ValueType ? never : Key;
}[keyof T]
>;
export declare type Intersection<
T extends object,
U extends object
> = T extends any ? Pick<T, SetIntersection<keyof T, keyof U>> : never;
export declare type Diff<T extends object, U extends object> = Pick<
T,
SetDifference<keyof T, keyof U>
>;
export declare type Subtract<T extends T1, T1 extends object> = Pick<
T,
SetComplement<keyof T, keyof T1>
>;
export declare type Overwrite<
T extends object,
U extends object,
I = Diff<T, U> & Intersection<U, T>
> = Pick<I, keyof I>;
export declare type Assign<
T extends object,
U extends object,
I = Diff<T, U> & Intersection<U, T> & Diff<U, T>
> = Pick<I, keyof I>;
export declare type Exact<A extends object> = A & {
__brand: keyof A;
};
export declare type Unionize<T extends object> = {
[P in keyof T]: {
[Q in P]: T[P];
};
}[keyof T];
export declare type PromiseType<T extends Promise<any>> = T extends Promise<
infer U
>
? U
: never;
export declare type DeepReadonly<T> = T extends (...args: any[]) => any
? T
: T extends any[]
? _DeepReadonlyArray<T[number]>
: T extends object
? _DeepReadonlyObject<T>
: T;
export interface _DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> {}
export declare type _DeepReadonlyObject<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};
export declare type DeepRequired<T> = T extends (...args: any[]) => any
? T
: T extends any[]
? _DeepRequiredArray<T[number]>
: T extends object
? _DeepRequiredObject<T>
: T;
export interface _DeepRequiredArray<T>
extends Array<DeepRequired<NonUndefined<T>>> {}
export declare type _DeepRequiredObject<T> = {
[P in keyof T]-?: DeepRequired<NonUndefined<T[P]>>;
};
export declare type DeepNonNullable<T> = T extends (...args: any[]) => any
? T
: T extends any[]
? _DeepNonNullableArray<T[number]>
: T extends object
? _DeepNonNullableObject<T>
: T;
export interface _DeepNonNullableArray<T>
extends Array<DeepNonNullable<NonNullable<T>>> {}
export declare type _DeepNonNullableObject<T> = {
[P in keyof T]-?: DeepNonNullable<NonNullable<T[P]>>;
};
export declare type DeepPartial<T> = T extends Function
? T
: T extends Array<infer U>
? _DeepPartialArray<U>
: T extends object
? _DeepPartialObject<T>
: T | undefined;
export interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {}
export declare type _DeepPartialObject<T> = {
[P in keyof T]?: DeepPartial<T[P]>;
};