forked from kolodny/immutability-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
51 lines (51 loc) · 1.67 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export declare class Context {
private commands;
constructor();
isEquals: (x: any, y: any) => boolean;
extend<T>(directive: string, fn: (param: any, old: T) => T): void;
update<T, C extends CustomCommands<object> = never>(object: T, $spec: Spec<T, C>): T;
}
export declare const isEquals: any;
export declare const extend: <T>(directive: string, fn: (param: any, old: T) => T) => void;
declare const _default: <T, C extends CustomCommands<object> = never>(object: T, $spec: Spec<T, C>) => T;
export default _default;
export declare type CustomCommands<T> = T & {
__noInferenceCustomCommandsBrand: any;
};
export declare type Spec<T, C extends CustomCommands<object> = never> = (T extends (Array<infer U> | ReadonlyArray<infer U>) ? ArraySpec<U, C> : T extends (Map<infer K, infer V> | ReadonlyMap<infer K, infer V>) ? MapSpec<K, V> : T extends (Set<infer X> | ReadonlySet<infer X>) ? SetSpec<X> : T extends object ? ObjectSpec<T, C> : never) | {
$set: T;
} | {
$apply: (v: T) => T;
} | ((v: T) => T) | (C extends CustomCommands<infer O> ? O : never);
declare type ArraySpec<T, C extends CustomCommands<object>> = {
$push: T[];
} | {
$unshift: T[];
} | {
$splice: Array<[number, number?] | [number, number, ...T[]]>;
} | {
[index: string]: Spec<T, C>;
};
declare type MapSpec<K, V> = {
$add: Array<[K, V]>;
} | {
$remove: K[];
} | {
[key: string]: {
$set: V;
};
};
declare type SetSpec<T> = {
$add: T[];
} | {
$remove: T[];
};
declare type ObjectSpec<T, C extends CustomCommands<object>> = {
$toggle: Array<keyof T>;
} | {
$unset: Array<keyof T>;
} | {
$merge: Partial<T>;
} | {
[K in keyof T]?: Spec<T[K], C>;
};