-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
500173d
commit 2079db9
Showing
5 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @file Type Tests - IfUnknown | ||
* @module tutils/types/tests/unit-d/IfUnknown | ||
*/ | ||
|
||
import type TestSubject from '../if-unknown' | ||
|
||
describe('unit-d:types/IfUnknown', () => { | ||
type False = false | ||
type True = true | ||
|
||
it('should equal False if IsUnknown<T> extends false', () => { | ||
expectTypeOf<TestSubject<unknown[], True, False>>().toEqualTypeOf<False>() | ||
}) | ||
|
||
it('should equal True if IsUnknown<T> extends true', () => { | ||
expectTypeOf<TestSubject<unknown, True, False>>().toEqualTypeOf<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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @file Type Tests - IsUnknown | ||
* @module tutils/types/tests/unit-d/IsUnknown | ||
*/ | ||
|
||
import type TestSubject from '../is-unknown' | ||
|
||
describe('unit-d:types/IsUnknown', () => { | ||
it('should equal false if T is not unknown', () => { | ||
expectTypeOf<TestSubject<null>>().toEqualTypeOf<false>() | ||
}) | ||
|
||
it('should equal true if T is unknown', () => { | ||
expectTypeOf<TestSubject<unknown>>().toEqualTypeOf<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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @file Type Definitions - IfUnknown | ||
* @module tutils/types/IfUnknown | ||
*/ | ||
|
||
import type IsUnknown from './is-unknown' | ||
|
||
/** | ||
* Conditional type that resolves depending on whether or not `T` is type | ||
* `unknown`. | ||
* | ||
* @see {@linkcode IsUnknown} | ||
* | ||
* @template T - Type to evaluate | ||
* @template True - Type if `T` is type `unknown` | ||
* @template False - Type if `T` is not type `unknown` | ||
*/ | ||
type IfUnknown<T, True, False> = IsUnknown<T> extends true ? True : False | ||
|
||
export type { IfUnknown as default } |
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,19 @@ | ||
/** | ||
* @file Type Definitions - IsUnknown | ||
* @module tutils/types/IsUnknown | ||
*/ | ||
|
||
import type IsNull from './is-null' | ||
|
||
/** | ||
* Returns a boolean indicating if `T` is type `unknown`. | ||
* | ||
* @template T - Type to evaluate | ||
*/ | ||
type IsUnknown<T> = unknown extends T | ||
? IsNull<T> extends false | ||
? true | ||
: false | ||
: false | ||
|
||
export type { IsUnknown as default } |