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

IsBivariant #971

Open
1 task done
innermatrix opened this issue Oct 23, 2024 · 0 comments
Open
1 task done

IsBivariant #971

innermatrix opened this issue Oct 23, 2024 · 0 comments

Comments

@innermatrix
Copy link

innermatrix commented Oct 23, 2024

Type description + examples

Most of the time when I want to test for equality, I actually care about mutual assignability (aka bivariance), not exact equality.

import {IsEqual, And} from 'type-fest'

type IsBivariant<T1, T2> = And<T1 extends T2 ? true : false, T2 extends T1 ? true : false>;

type T1 = { k: string }
type T2 = { k: string }
type T3 = T1 | T2

type test1 = IsEqual<T1, T3>; // false
type test2 = IsBivariant<T1, T3>; // true

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbwJIGcCiBHArgQwDYA0cAggHYAmAvnAGZQQhwDkMAnmAKYC0NHKMTAFCC2nOKgBCwAG44owHKRgAeACoBGIqoBMAPjgBeEhTXq4HAB4wOFFHB1wA-HBhQsHOAC5a+FBy3a5lY25HYaTi5uHt40vhy6ANzCoh7hRghwANbe-PKkAOZwlCLsqYHpWTmuwAVFJWKqAMyG9mYAPvbayaUufDBmRqiYuHimWo2JcAD0Uz54fvUe1vzl4ihSsvKKKhrjkzOR7sJAA

Type source

No response

Search existing types and issues first

  • I tried my best to look for it

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant