-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
20 changed files
with
600 additions
and
303 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,74 @@ | ||
import { it } from '@jest/globals' | ||
import { testType, type IsFalse } from '../index.js' | ||
import { testType, type IsFalse, type $Then, type $Else } from '../index.js' | ||
|
||
it('returns true if T is false', () => { | ||
testType.true<IsFalse<false>>(true) | ||
testType.equal<IsFalse<false>, true>(true) | ||
}) | ||
|
||
it('returns false if T is boolean or true', () => { | ||
testType.false<IsFalse<boolean>>(true) | ||
testType.false<IsFalse<true>>(true) | ||
it('returns boolean if T is boolean because it is distributive by default', () => { | ||
testType.equal<IsFalse<boolean>, boolean>(true) | ||
testType.equal<IsFalse<boolean, { distributive: false }>, false>(true) | ||
}) | ||
|
||
it('returns false if T is true', () => { | ||
testType.equal<IsFalse<true>, false>(true) | ||
}) | ||
|
||
it('returns false for special types', () => { | ||
testType.false<IsFalse<void>>(true) | ||
testType.false<IsFalse<unknown>>(true) | ||
testType.false<IsFalse<any>>(true) | ||
testType.false<IsFalse<never>>(true) | ||
testType.equal<IsFalse<void>, false>(true) | ||
testType.equal<IsFalse<unknown>, false>(true) | ||
testType.equal<IsFalse<any>, false>(true) | ||
testType.equal<IsFalse<never>, false>(true) | ||
}) | ||
|
||
it('returns false for other types', () => { | ||
testType.false<IsFalse<undefined>>(true) | ||
testType.false<IsFalse<null>>(true) | ||
testType.false<IsFalse<number>>(true) | ||
testType.false<IsFalse<1>>(true) | ||
testType.false<IsFalse<string>>(true) | ||
testType.false<IsFalse<''>>(true) | ||
testType.false<IsFalse<symbol>>(true) | ||
testType.false<IsFalse<bigint>>(true) | ||
testType.false<IsFalse<1n>>(true) | ||
testType.false<IsFalse<{}>>(true) | ||
testType.false<IsFalse<{ a: 1 }>>(true) | ||
testType.false<IsFalse<string[]>>(true) | ||
testType.false<IsFalse<[]>>(true) | ||
testType.false<IsFalse<Function>>(true) | ||
testType.false<IsFalse<() => void>>(true) | ||
}) | ||
|
||
it('returns false for union type', () => { | ||
testType.false<IsFalse<false | 1>>(true) | ||
testType.false<IsFalse<false | boolean>>(true) | ||
}) | ||
|
||
it('returns false for intersection type', () => { | ||
testType.false<IsFalse<false & { a: 1 }>>(true) | ||
}) | ||
|
||
it('can override Then/Else', () => { | ||
testType.equal<IsFalse<false, 1, 2>, 1>(true) | ||
|
||
testType.equal<IsFalse<any, 1, 2>, 2>(true) | ||
testType.equal<IsFalse<unknown, 1, 2>, 2>(true) | ||
testType.equal<IsFalse<never, 1, 2>, 2>(true) | ||
testType.equal<IsFalse<void, 1, 2>, 2>(true) | ||
testType.equal<IsFalse<undefined>, false>(true) | ||
testType.equal<IsFalse<null>, false>(true) | ||
testType.equal<IsFalse<number>, false>(true) | ||
testType.equal<IsFalse<1>, false>(true) | ||
testType.equal<IsFalse<string>, false>(true) | ||
testType.equal<IsFalse<''>, false>(true) | ||
testType.equal<IsFalse<symbol>, false>(true) | ||
testType.equal<IsFalse<bigint>, false>(true) | ||
testType.equal<IsFalse<1n>, false>(true) | ||
testType.equal<IsFalse<{}>, false>(true) | ||
testType.equal<IsFalse<{ a: 1 }>, false>(true) | ||
testType.equal<IsFalse<string[]>, false>(true) | ||
testType.equal<IsFalse<[]>, false>(true) | ||
testType.equal<IsFalse<Function>, false>(true) | ||
testType.equal<IsFalse<() => void>, false>(true) | ||
}) | ||
|
||
it('distributes over union type', () => { | ||
testType.equal<IsFalse<false | 1>, boolean>(true) | ||
}) | ||
|
||
it('can disable union distribution', () => { | ||
testType.equal<IsFalse<false | 1, { distributive: false }>, false>(true) | ||
}) | ||
|
||
it('returns true for intersection type', () => { | ||
testType.equal<IsFalse<false & { a: 1 }>, true>(true) | ||
}) | ||
|
||
it('works as filter', () => { | ||
testType.equal<IsFalse<false, { selection: 'filter' }>, false>(true) | ||
testType.equal<IsFalse<true, { selection: 'filter' }>, never>(true) | ||
testType.equal<IsFalse<boolean, { selection: 'filter' }>, false>(true) | ||
testType.equal<IsFalse<boolean, { selection: 'filter', distributive: false }>, never>(true) | ||
|
||
testType.equal<IsFalse<never, { selection: 'filter' }>, never>(true) | ||
testType.equal<IsFalse<unknown, { selection: 'filter' }>, never>(true) | ||
testType.equal<IsFalse<string | false, { selection: 'filter' }>, false>(true) | ||
|
||
testType.equal<IsFalse<string | true, { selection: 'filter' }>, never>(true) | ||
}) | ||
|
||
it('works with unique branches', () => { | ||
testType.equal<IsFalse<false, IsFalse.$Branch>, $Then>(true) | ||
|
||
testType.equal<IsFalse<any, IsFalse.$Branch>, $Else>(true) | ||
testType.equal<IsFalse<unknown, IsFalse.$Branch>, $Else>(true) | ||
testType.equal<IsFalse<never, IsFalse.$Branch>, $Else>(true) | ||
testType.equal<IsFalse<void, IsFalse.$Branch>, $Else>(true) | ||
}) |
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
Oops, something went wrong.