fix diffArrays option type

This commit is contained in:
Yuto Suzuki
2018-11-01 22:48:03 +09:00
parent f01ba112a9
commit 900bb09091
2 changed files with 26 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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
@@ -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 {