You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect result from isDeepStrictEqual on two different Sets #61386
With these two inputs, isDeepStrictEqual works as expected:
Welcome to Node.js v22.21.1.
Type ".help" for more information.
> a = new Set([1, 2])
Set(2) { 1, 2 }
> b = new Set([1, new Set([2])])
Set(2) { 1, Set(1) { 2 } }
> require('util').isDeepStrictEqual(a, b)
false
> require('util').isDeepStrictEqual(b, a)
false
This is a case specific to mixed primitive / object cases. I will open a fix tomorrow, I identified the issue in the code. It also applies the same to maps.
Activity
ljharb commentedon Jan 14, 2026
I wouldn't expect any of those to return true, personally -
new Set([1, 2])andnew Set([1, new Set(2)])aren't the same.DoubleClickPreferred commentedon Jan 14, 2026
With these two inputs, isDeepStrictEqual works as expected:
It looks like the bug happens with deeper sets.
ljharb commentedon Jan 14, 2026
I mean it's clearly a bug - but "strict deep equal" shouldn't be equating
new Set(xs)withxsin the first place.BridgeAR commentedon Jan 15, 2026
This is a case specific to mixed primitive / object cases. I will open a fix tomorrow, I identified the issue in the code. It also applies the same to maps.
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types
assert,util: fix deep comparison for sets and maps with mixed types