forked from mattphillips/deep-object-diff
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
37 lines (28 loc) · 1.05 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
type DeepPartial<T> = {
[K in keyof T]?: DeepPartial<T[K]>
}
interface IDictionary<T> {
[key: string]: T;
}
/*
In "deep-object-diff" there're 2 scenarios for a property diff:
1. If the property is an object or primitive, the diff is a deep partial;
2. If the property is an array, the diff is a dictionary.
Its keys are indices, and the values are deep partials of the change.
*/
type PropertyDiff<T> = T extends Array<infer Elem>
? IDictionary<Elem>
: DeepPartial<T>;
export type Diff<T> = {
[P in keyof T]?: PropertyDiff<T[P]>;
};
export interface IDetailedDiff<T> {
added: Diff<T>;
deleted: Diff<T>;
updated: Diff<T>;
}
export function diff<T> (originalObj: T, updatedObj: T): Diff<T>
export function addedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
export function deletedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
export function updatedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
export function detailedDiff<T> (originalObj: T, updatedObj: T): IDetailedDiff<T>