The _.isMatchWith
function from the Lodash library checks if object
is a partial deep match with source
using a customizer function. This function is useful when we want to compare custom properties on objects that require a specific comparison logic. Here's an example of how to use the function with TypeScript:
index.ts1091 chars54 lines
In the example above, we define an interface for a Person
object with nested address
properties. We then define two Person
objects john
and jane
, and two partial matches partialJane
and partialJohn
, which we'll use to compare them.
Next, we define a customizer function streetOnly
that filters by street
only. We wrap the comparison of the street property in an isEqualWith
statement because we need to recurse through the nested objects. Finally, we test our function by comparing john
to partialJane
and partialJohn
, respectively.
gistlibby LogSnag