Skip to content

Commit

Permalink
Merge pull request DefinitelyTyped#30221 from moc-yuto/diff
Browse files Browse the repository at this point in the history
fix [diff] diffArrays option type
  • Loading branch information
DanielRosenwasser authored Nov 5, 2018
2 parents 116fd22 + 900bb09 commit 9a30514
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions types/diff/diff-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ diffArraysResult.forEach(result => {
}
});

interface DiffObj {
value: number;
}
const a: DiffObj = {value: 0};
const b: DiffObj = {value: 1};
const c: DiffObj = {value: 2};
const d: DiffObj = {value: 3};
const arrayOptions: jsdiff.IArrayOptions = {
comparator: (left: DiffObj, right: DiffObj) => {
return left.value === right.value;
}
};
const diffResult = jsdiff.diffArrays([a, b, c], [a, b, d], arrayOptions);
diffResult.forEach(result => {
if (result.added) {
console.log(`added ${result.value.length} line(s):`, ...result.value);
} else if (result.removed) {
console.log(`removed ${result.value.length} line(s):`, ...result.value);
} else {
console.log(`no changes`);
}
});

// --------------------------

class LineDiffWithoutWhitespace extends jsdiff.Diff {
Expand Down
5 changes: 3 additions & 2 deletions types/diff/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/kpdecker/jsdiff
// Definitions by: vvakame <https://github.com/vvakame>
// szdc <https://github.com/szdc>
// moc-yuto <https://github.com/moc-yuto>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

Expand All @@ -18,8 +19,8 @@ declare namespace JsDiff {
newlineIsToken?: boolean;
}

interface IArrayOptions extends IOptions {
comparator?: (left: any, right: any) => number;
interface IArrayOptions {
comparator?: (left: any, right: any) => boolean;
}

interface IDiffResult {
Expand Down

0 comments on commit 9a30514

Please sign in to comment.