forked from tada5hi/smob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.ts
60 lines (52 loc) · 1.43 KB
/
type.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
import type { PriorityName } from './constants';
type UnionToIntersection<U> =
(U extends any ? (k: U) => void : never) extends ((k: infer I)=>void) ? I : never;
export type Options = {
/**
* Merge object array properties.
*
* default: true
*/
array: boolean,
/**
* Remove duplicates, when merging array elements.
*
* default: false
*/
arrayDistinct: boolean,
/**
* Strategy to merge different object keys.
*
* @param target
* @param key
* @param value
*/
strategy?: (target: Record<string, any>, key: string, value: unknown) => Record<string, any> | undefined,
/**
* Merge sources in place.
*
* default: false
*/
inPlace?: boolean
/**
* Deep clone input sources.
*
* default: false
*/
clone?: boolean,
/**
* Merge sources from left-to-right or right-to-left.
*
* default: left
*/
priority: `${PriorityName}`
};
export type OptionsInput = Partial<Options>;
export type MergerSource = any[] | Record<string, any>;
export type MergerSourceUnwrap<T extends MergerSource> = T extends Array<infer Return> ? Return : T;
export type MergerResult<B extends MergerSource> = UnionToIntersection<MergerSourceUnwrap<B>>;
export type MergerContext = {
options: Options,
map: WeakMap<any, any>
};
export type Merger = <B extends MergerSource[]>(...sources: B) => MergerResult<B>;