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

Sign up
Appearance settings

Commit 71b28b8

Browse files
Typescript definitions
1 parent 6296889 commit 71b28b8

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

‎index.d.ts‎

Lines 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)

AltStyle によって変換されたページ (->オリジナル) /