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

IsEqual identity issues #537

Closed
trevorade opened this issue Jan 6, 2023 · 2 comments · Fixed by #1012
Closed

IsEqual identity issues #537

trevorade opened this issue Jan 6, 2023 · 2 comments · Fixed by #1012
Labels
bug Something isn't working

Comments

@trevorade
Copy link
Contributor

trevorade commented Jan 6, 2023

There are two self-identity bugs that can pretty simply be fixed: TS Playground

Both of these evaluate to false:

IsEqual<{a: 1} & {a: 1}, {a: 1}>
IsEqual<{a: 1} | {a: 1}, {a: 1}>

The fix is to expand the check a touch:

type IsEqual<A, B> =
    (<G>() => G extends A & G | G ? 1 : 2) extends
    (<G>() => G extends B & G | G ? 1 : 2)
    ? true
    : false;

There's also this intersection bug but I'm unaware of a fix: TS Playground

This evaluates to false:

IsEqual<{a: 1} & {b: 2}, {a: 1, b: 2}>

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@tommy-mitchell
Copy link
Contributor

microsoft/TypeScript#27024 (comment) has a robust solution that seems to solve this (TS Playground link). It's a much longer type though, and seemingly not perfect either.

@tommy-mitchell
Copy link
Contributor

Seemingly, according to Update 1 on this StackOverflow answer, under TypeScript's implementation {a: 1} & {b: 2} and {a: 1, b: 2} aren't actually the same. Not sure if that means they should or shouldn't be equal on the type level, though.

microsoft/TypeScript#48100 is an open issue tracking type equality and its definition. Seems that a recursive Simplify can fix some issues with equality as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants