diff --git a/types/shallowequal/index.d.ts b/types/shallowequal/index.d.ts index 95b91d6de5..4d111eb332 100644 --- a/types/shallowequal/index.d.ts +++ b/types/shallowequal/index.d.ts @@ -2,14 +2,24 @@ // Project: https://github.com/dashed/shallowequal // Definitions by: Sean Kelley // BendingBender +// Arnd Issler // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 declare function shallowEqual( objA: any, objB: any, - compare?: (this: TCtx, objA: any, objB: any, indexOrKey?: number | string) => boolean | void, + customizer?: shallowEqual.Customizer, compareContext?: TCtx ): boolean; +declare namespace shallowEqual { + type Customizer = ( + this: T, + objA: any, + objB: any, + indexOrKey?: number | string + ) => boolean | void; +} + export = shallowEqual; diff --git a/types/shallowequal/shallowequal-tests.ts b/types/shallowequal/shallowequal-tests.ts index efa5b546a5..6d30381472 100644 --- a/types/shallowequal/shallowequal-tests.ts +++ b/types/shallowequal/shallowequal-tests.ts @@ -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 = () => undefined; + +const customizer: shallowEqual.Customizer = 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