-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.d.ts
33 lines (27 loc) · 806 Bytes
/
index.d.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
type UndefinedKeys<T> = {
[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T];
type OptionalObject<T> = Omit<T, UndefinedKeys<T>> &
Partial<Pick<T, UndefinedKeys<T>>> extends infer R
? { [K in keyof R]: Exclude<R[K], undefined> }
: never;
declare namespace rAssign {
type TransformFunction<T = any> = (
value?: unknown,
key?: string,
source?: unknown
) => T;
type TransformSchema<T = any> = {
[key in keyof T]: TransformFunction<T[key]>;
};
type InferType<S extends TransformSchema> = OptionalObject<{
[key in keyof S]: ReturnType<S[key]>;
}>;
}
/**
* Assign object properties and transform result based on the provided schema
*/
declare function rAssign<
S extends rAssign.TransformSchema
>(schema: S, ...sources: unknown[]): rAssign.InferType<S>;
export = rAssign;