Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
Returns a boolean for whether the two given types are equal. | ||
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650 | ||
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796 | ||
@example | ||
``` | ||
import type {IsEqual} from 'type-fest'; | ||
type Expect<T extends true> = T | ||
type Case = Expect<IsEqual<Uppercase<"sample">, "SAMPLE">> | ||
``` | ||
@category Utilities | ||
*/ | ||
export type IsEqual<X, Y> = | ||
(<G>() => G extends X ? 1 : 2) extends | ||
(<G>() => G extends Y ? 1 : 2) | ||
? true | ||
: false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {expectError, expectType} from 'tsd'; | ||
import type {IsEqual} from '../index'; | ||
|
||
const notEqualNumberAndString: IsEqual<number, string> = false; | ||
expectType<false>(notEqualNumberAndString); | ||
|
||
const equalNumbers: IsEqual<1, 1> = true; | ||
expectType<true>(equalNumbers); | ||
|
||
const notEqualAnyAndNumber: IsEqual<any, number> = false; | ||
expectType<false>(notEqualAnyAndNumber); | ||
|
||
const notEqualUnionAndNumber: IsEqual<1 | 2, 1> = false; | ||
expectType<false>(notEqualUnionAndNumber); | ||
|
||
const notEqualAnyAndNever: IsEqual<any, never> = false; | ||
expectType<false>(notEqualAnyAndNever); | ||
|
||
const notEqualArrayOfAnyAndArrayOfNever: IsEqual<[any], [never]> = false; | ||
expectType<false>(notEqualArrayOfAnyAndArrayOfNever); | ||
|
||
declare const anything: any; | ||
|
||
// Missing all generic parameters. | ||
expectError<IsEqual>(anything); | ||
|
||
// Missing `Y` generic parameter. | ||
expectError<IsEqual<number>>(anything); |