[@types/shallowequal] separate shallowequal.customizer

This commit is contained in:
Arnd Issler
2019-02-02 21:20:01 +01:00
parent f1eed296d2
commit b9aeb08f81
2 changed files with 33 additions and 2 deletions
+11 -1
View File
@@ -2,14 +2,24 @@
// Project: https://github.com/dashed/shallowequal
// Definitions by: Sean Kelley <https://github.com/seansfkelley>
// BendingBender <https://github.com/BendingBender>
// Arnd Issler <https://github.com/arndissler>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
declare function shallowEqual<TCtx = any>(
objA: any,
objB: any,
compare?: (this: TCtx, objA: any, objB: any, indexOrKey?: number | string) => boolean | void,
customizer?: shallowEqual.Customizer<TCtx>,
compareContext?: TCtx
): boolean;
declare namespace shallowEqual {
type Customizer<T = any> = (
this: T,
objA: any,
objB: any,
indexOrKey?: number | string
) => boolean | void;
}
export = shallowEqual;
+22 -1
View File
@@ -12,13 +12,34 @@ shallowEqual(a, b, (a, b, indexOrKey) => {
return false;
});
shallowEqual(a, b, () => {}); // $ExpectType boolean
shallowEqual(a, b, () => undefined); // $ExpectType boolean
// $ExpectType boolean
shallowEqual(
a,
b,
function() {
this; // $ExpectType { foo: string; }
return undefined;
},
{ foo: 'bar' }
);
interface Foo {
foo: string;
bar: number;
}
const c: Foo = { foo: 'foo', bar: 0 };
const d: Foo = { foo: 'baz', bar: 1 };
const undefinedCustomizer: shallowEqual.Customizer<Foo> = () => undefined;
const customizer: shallowEqual.Customizer<Foo> = function(a: any, b: any) {
this; // $ExpectType Foo
a; // $ExpectType any
b; // $ExpectType any
return undefined;
};
shallowEqual(c, d, undefinedCustomizer); // $ExpectType boolean
shallowEqual(c, d, customizer); // $ExpectType boolean