Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Type definition mismatch isMatchWith customizer function #5991

Copy link
Copy link
Open
@NapolDeveloper

Description

@NapolDeveloper
Issue body actions

Type definition mismatch: isMatchWith customizer function allows truthy/falsy values but TypeScript types restrict to boolean/undefined

Description

There's an inconsistency between Lodash's actual implementation of isMatchWith and its TypeScript type definitions. The current TypeScript definition restricts the customizer function's return type to boolean | undefined, but Lodash's own test cases and implementation suggest it actually accepts any value and treats them as truthy/falsy.

TypeScript Definition

The current type definition in @types/lodash for isMatchWith customizer:

interface IsMatchWithCustomizer {
  (value: any, other: any, indexOrKey: PropertyName, object: object, source: object): boolean | undefined;
}

declare function isMatchWith(
  object: object,
  source: object,
  customizer: IsMatchWithCustomizer
): boolean;

Error Example
When trying to use Lodash's own test utility function with TypeScript:

import { isMatchWith } from 'lodash';

// This is a utility function similar to one used in Lodash's own tests
const stubA = function() {
  return 'a'; // Returns a string, not a boolean
};

const object = { a: 1 };
let actual = isMatchWith(object, { a: 1 }, stubA);

This code produces the following TypeScript error:

Type '() => string' is not assignable to parameter of type 'IsMatchWithCustomizer'.
  Type 'string' is not assignable to type 'boolean | undefined'.ts(2345)

Actual Behavior
Looking at Lodash's own test cases in v5-wip branch, it's clear that the implementation is designed to work with any truthy/falsy values, not just booleans. For example, from Lodash's test:

it('should return a boolean value even when `customizer` does not', () => {
  const object = { a: 1 };
  let actual = isMatchWith(object, { a: 1 }, stubA);
  expect(actual).toBe(true); // passed
  // More tests...
});

Image
If you don't mind, I'd like to redefine that type. If possible, please let me know your contribution guide!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.