#1881·es-toolkit

isEqual: false negative on equal Maps/Sets with duplicate-shaped keys (deviates from lodash)

Author: XyraSinclairCreated Jul 11, 2026Updated Jul 11, 2026

isEqual returns false for genuinely equal Maps when multiple keys are structurally equal — and deviates from lodash, which returns true:

typescript
import { isEqual } from 'es-toolkit';
import lodashIsEqual from 'lodash/isEqual';

const A = new Map([[{}, 1], [{}, 2]]);
const B = new Map([[{}, 2], [{}, 1]]);
// Both maps hold the same multiset of entries: ({} → 1) and ({} → 2).

isEqual(A, B);       // false ❌
lodashIsEqual(A, B); // true  ✅

The cause is greedy key matching: each key of A is paired with the first structurally-equal key of B and never reconsidered, so when that first pairing has mismatched values the comparison fails even though a valid pairing exists. Sets with duplicate-shaped elements hit the same path.

In an 8,000-pair differential fuzz over random Map/Set/object/array data (adjudicated by an exhaustive backtracking matcher), roughly 10% of genuinely-equal collection pairs came back false from this class — it fires whenever a collection contains two entries whose keys are structurally equal but whose values differ per pairing.

Deciding these cases correctly requires backtracking (or grouping equal keys and matching values as a multiset) rather than first-match-wins. Happy to provide the fuzz corpus or more failing cases if useful.