Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1e9c938

Browse filesBrowse files
authored
Merge pull request #1 from nikolayg/master
Typescript definitions
2 parents 944656d + 71b28b8 commit 1e9c938
Copy full SHA for 1e9c938

File tree

Expand file treeCollapse file tree

1 file changed

+33
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+33
-5
lines changed

‎index.d.ts

Copy file name to clipboard
+33-5Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1-
export function diff (originalObj: object, updatedObj: object): object
1+
type DeepPartial<T> = {
2+
[K in keyof T]?: DeepPartial<T[K]>
3+
}
24

3-
export function addedDiff (originalObj: object, updatedObj: object): object
5+
interface IDictionary<T> {
6+
[key: string]: T;
7+
}
48

5-
export function deletedDiff (originalObj: object, updatedObj: object): object
9+
/*
10+
In "deep-object-diff" there're 2 scenarios for a property diff:
11+
1. If the property is an object or primitive, the diff is a deep partial;
12+
2. If the property is an array, the diff is a dictionary.
13+
Its keys are indices, and the values are deep partials of the change.
14+
*/
15+
type PropertyDiff<T> = T extends Array<infer Elem>
16+
? IDictionary<Elem>
17+
: DeepPartial<T>;
618

7-
export function updatedDiff (originalObj: object, updatedObj: object): object
19+
export type Diff<T> = {
20+
[P in keyof T]?: PropertyDiff<T[P]>;
21+
};
822

9-
export function detailedDiff (originalObj: object, updatedObj: object): object
23+
export interface IDetailedDiff<T> {
24+
added: Diff<T>;
25+
deleted: Diff<T>;
26+
updated: Diff<T>;
27+
}
28+
29+
export function diff<T> (originalObj: T, updatedObj: T): Diff<T>
30+
31+
export function addedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
32+
33+
export function deletedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
34+
35+
export function updatedDiff<T> (originalObj: T, updatedObj: T): Diff<T>
36+
37+
export function detailedDiff<T> (originalObj: T, updatedObj: T): IDetailedDiff<T>

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.