From 71b28b81e3c18c054943cfdfe414d6390e9c36bf Mon Sep 17 00:00:00 2001
From: Nikolay <nikolay.grozev@gmail.com>
Date: Fri, 12 Jul 2019 17:24:05 +1000
Subject: [PATCH] Typescript definitions

---
 index.d.ts | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)

diff --git a/index.d.ts b/index.d.ts
index e848bff..4b62032 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,9 +1,37 @@
-export function diff (originalObj: object, updatedObj: object): object
+type DeepPartial<T> = { 
+    [K in keyof T]?: DeepPartial<T[K]> 
+}
 
-export function addedDiff (originalObj: object, updatedObj: object): object
+interface IDictionary<T> {
+    [key: string]: T;
+}
 
-export function deletedDiff (originalObj: object, updatedObj: object): object
+/* 
+ 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 function updatedDiff (originalObj: object, updatedObj: object): object
+export type Diff<T> = {
+    [P in keyof T]?: PropertyDiff<T[P]>;
+};
 
-export function detailedDiff (originalObj: object, updatedObj: object): object
+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>