1 | import type { Head, Tail } from "./tuple.js";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type SomeRequired<T, K extends keyof T> = Partial<Omit<T, K>> & Required<Pick<T, K>>;
|
7 |
|
8 |
|
9 |
|
10 | export type TypedKeys<A, B> = {
|
11 | [P in Keys<A>]: B extends A[P] ? P : never;
|
12 | }[keyof A];
|
13 | export type NumericKeys<T> = TypedKeys<T, number>;
|
14 | export type StringKeys<T> = TypedKeys<T, string>;
|
15 | export type DeepPartial<T> = Partial<{
|
16 | [k in keyof T]: DeepPartial<T[k]>;
|
17 | }>;
|
18 | export type Keys<T> = keyof Required<T>;
|
19 | export type Keys1<T, A extends Keys<T>> = Keys<Required<T>[A]>;
|
20 | export type Keys2<T, A extends Keys<T>, B extends Keys1<T, A>> = Keys1<Required<T>[A], B>;
|
21 | export type Keys3<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>> = Keys2<Required<T>[A], B, C>;
|
22 | export type Keys4<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>> = Keys3<Required<T>[A], B, C, D>;
|
23 | export type Keys5<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>> = Keys4<Required<T>[A], B, C, D, E>;
|
24 | export type Keys6<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>> = Keys5<Required<T>[A], B, C, D, E, F>;
|
25 | export type Keys7<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>> = Keys6<Required<T>[A], B, C, D, E, F, G>;
|
26 | export type Keys8<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, H extends Keys7<T, A, B, C, D, E, F, G>> = Keys7<Required<T>[A], B, C, D, E, F, G, H>;
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | type KeysNReducer<T, L, R extends unknown[]> = L extends keyof T ? {
|
37 | 0: keyof Required<T>[L];
|
38 | 1: KeysNReducer<Required<T>[L], Head<R>, Tail<R>>;
|
39 | }[R extends [] ? 0 : 1] : never;
|
40 |
|
41 |
|
42 |
|
43 | export type KeysN<T, L extends unknown[]> = L extends [] ? Keys<T> : KeysNReducer<T, Head<L>, Tail<L>>;
|
44 |
|
45 |
|
46 |
|
47 | export type Values<T> = Val1<T, Keys<T>>;
|
48 | export type Val1<T, A extends Keys<T>> = T[A];
|
49 | export type Val2<T, A extends Keys<T>, B extends Keys1<T, A>> = ValN<T, [A, B]>;
|
50 | export type Val3<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>> = ValN<T, [A, B, C]>;
|
51 | export type Val4<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>> = ValN<T, [A, B, C, D]>;
|
52 | export type Val5<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>> = ValN<T, [A, B, C, D, E]>;
|
53 | export type Val6<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>> = ValN<T, [A, B, C, D, E, F]>;
|
54 | export type Val7<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>> = ValN<T, [A, B, C, D, E, F, G]>;
|
55 | export type Val8<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, H extends Keys7<T, A, B, C, D, E, F, G>> = ValN<T, [A, B, C, D, E, F, G, H]>;
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | type ValNReducer<T, C, R extends unknown[]> = C extends keyof T ? {
|
66 | 0: T[C];
|
67 | 1: ValNReducer<Required<T>[C], Head<R>, Tail<R>>;
|
68 | }[R extends [] ? 0 : 1] : never;
|
69 |
|
70 |
|
71 |
|
72 | export type ValN<T, L extends unknown[]> = L extends [] ? T : ValNReducer<T, Head<L>, Tail<L>>;
|
73 |
|
74 |
|
75 |
|
76 | export type Without<T, A extends Keys<T>> = Omit<T, A>;
|
77 | export type Without2<T, A extends Keys<T>, B extends Keys1<T, A>> = Without<T, A> & {
|
78 | [id in A]: Without<Val1<T, A>, B>;
|
79 | };
|
80 | export type Without3<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>> = Without<T, A> & {
|
81 | [id in A]: Without2<Val1<T, A>, B, C>;
|
82 | };
|
83 | export type Without4<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>> = Without<T, A> & {
|
84 | [id in A]: Without3<Val1<T, A>, B, C, D>;
|
85 | };
|
86 | export type Without5<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>> = Without<T, A> & {
|
87 | [id in A]: Without4<Val1<T, A>, B, C, D, E>;
|
88 | };
|
89 | export type Without6<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>> = Without<T, A> & {
|
90 | [id in A]: Without5<Val1<T, A>, B, C, D, E, F>;
|
91 | };
|
92 | export type Without7<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>> = Without<T, A> & {
|
93 | [id in A]: Without6<Val1<T, A>, B, C, D, E, F, G>;
|
94 | };
|
95 | export type Without8<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, H extends Keys7<T, A, B, C, D, E, F, G>> = Without<T, A> & {
|
96 | [id in A]: Without7<Val1<T, A>, B, C, D, E, F, G, H>;
|
97 | };
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | type WithoutNReducer<T, C, R extends unknown[]> = C extends keyof T ? {
|
108 | 0: Without<T, C>;
|
109 | 1: Without<T, C> & Record<C, WithoutNReducer<T[C], Head<R>, Tail<R>>>;
|
110 | }[R extends [] ? 0 : 1] : never;
|
111 |
|
112 |
|
113 |
|
114 | export type WithoutN<T, P extends unknown[]> = WithoutNReducer<T, Head<P>, Tail<P>>;
|
115 |
|
116 |
|
117 |
|
118 | export type Replace<T, A extends Keys<T>, V> = Without<T, A> & {
|
119 | [id in A]: V;
|
120 | };
|
121 | export type Replace2<T, A extends Keys<T>, B extends Keys1<T, A>, V> = Without<T, A> & {
|
122 | [id in A]: Replace<Val1<T, A>, B, V>;
|
123 | };
|
124 | export type Replace3<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, V> = Without<T, A> & {
|
125 | [id in A]: Replace2<Val1<T, A>, B, C, V>;
|
126 | };
|
127 | export type Replace4<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, V> = Without<T, A> & {
|
128 | [id in A]: Replace3<Val1<T, A>, B, C, D, V>;
|
129 | };
|
130 | export type Replace5<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, V> = Without<T, A> & {
|
131 | [id in A]: Replace4<Val1<T, A>, B, C, D, E, V>;
|
132 | };
|
133 | export type Replace6<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, V> = Without<T, A> & {
|
134 | [id in A]: Replace5<Val1<T, A>, B, C, D, E, F, V>;
|
135 | };
|
136 | export type Replace7<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, V> = Without<T, A> & {
|
137 | [id in A]: Replace6<Val1<T, A>, B, C, D, E, F, G, V>;
|
138 | };
|
139 | export type Replace8<T, A extends Keys<T>, B extends Keys1<T, A>, C extends Keys2<T, A, B>, D extends Keys3<T, A, B, C>, E extends Keys4<T, A, B, C, D>, F extends Keys5<T, A, B, C, D, E>, G extends Keys6<T, A, B, C, D, E, F>, H extends Keys7<T, A, B, C, D, E, F, G>, V> = Without<T, A> & {
|
140 | [id in A]: Replace7<Val1<T, A>, B, C, D, E, F, G, H, V>;
|
141 | };
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | type ReplaceNReducer<T, C, R extends unknown[], V> = C extends keyof T ? {
|
153 | 0: Replace<T, C, V>;
|
154 | 1: Without<T, C> & Record<C, ReplaceNReducer<T[C], Head<R>, Tail<R>, V>>;
|
155 | }[R extends [] ? 0 : 1] : never;
|
156 |
|
157 |
|
158 |
|
159 | export type ReplaceN<T, P extends unknown[], V> = ReplaceNReducer<T, Head<P>, Tail<P>, V>;
|
160 | export {};
|
161 |
|
\ | No newline at end of file |