Skip to content

Typescript definitions #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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>