mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 22:30:01 +00:00
fix diffArrays option type
This commit is contained in:
@@ -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 {
|
||||
|
||||
5
types/diff/index.d.ts
vendored
5
types/diff/index.d.ts
vendored
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user