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

feat: add Equal type of Comparison of equivalence #1167

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/typings/Equal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* In order to determine whether it is the same in the union type,
* the types are compared by wrapping them with a function with a generic type as a factor once more.
*
* ```ts
* type Answer = Equal<1 | 2, 1 | 2>; // true
* ```
*/
type Equal<X, Y> =
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
? true
: false;