Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can areEqual be undefined-safe too? #60

Open
malcolmredheron opened this issue Jul 28, 2022 · 2 comments
Open

Can areEqual be undefined-safe too? #60

malcolmredheron opened this issue Jul 28, 2022 · 2 comments

Comments

@malcolmredheron
Copy link
Contributor

As

* if possible, degrades to === if not available, and is also null-safe.
, says, areEqual is null-safe. However, the signature accepts undefined, and then it crashes if the undefined is in obj (versus obj2).

is there a reason that undefined isn't handled here? Or would you take a PR that changes this?

@emmanueltouzery
Copy link
Owner

hm at the time i didn't realize any included also undefined...

actually i think the right fix would be in hasEquals:

export function hasEquals(v: WithEquality): v is HasEquals {
    // there is a reason why we check only for equals, not for hashCode.
    // we want to decide which codepath to take: === or equals/hashcode.
    // if there is a equals function then we don't want ===, regardless of
    // whether there is a hashCode method or not. If there is a equals
    // and not hashCode, we want to go on the equals/hashCode codepath,
    // which will blow a little later at runtime if the hashCode is missing.
-    return ((<HasEquals>v).equals !== undefined);
+    return "equals" in v;
}

I'd definitely merge such a PR (assuming the tests pass and so on), and release shortly afterwards.

PS: sorry about the delay, I missed the notification during my holidays.

@emmanueltouzery
Copy link
Owner

Hmm actually I'm not sure anymore whether in is undefined-safe. But bottom line yes, a PR would be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants