mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 23:10:29 +00:00
[@types/shallowequal] separate shallowequal.customizer
This commit is contained in:
Vendored
+11
-1
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user