moroshko / shallow-equal

Minimalistic shallow equality check for arrays/objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array comparison allows primitives to pass

bdmason opened this issue · comments

If you pass two equal primitive to the array comparison method it'll return true. Perhaps add this at the top:

if (!Array.isArray(arrA) || !Array.isArray(arrB)) {
  return false
}

v3.0.0 adds Typescript support, which will generate a warning for people using Typescript (since shallowEqualArrays now expects any[] | null | undefined). This might reduce the benefit of explicitly checking via Array.isArray.

I'm open to, but unsure of, the bang-per-buck of adding this additional check to shallowEqualArrays, since the name so explicitly suggests you should call it only with arrays (especially now that TS also will help warn you). With v3, we've also added a generic shallowEqual, which definitely does the array checks you mentioned above, so this issue might be adequately addressed with all the latest changes.

@bdmason : LMK what you think.

Closing issue since recent changes should, in theory, make this less necessary. But please feel free to ping back if you feel differently!