-
-
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.
feat(types):
IsUndefined
, IfUndefined
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
59d4e0e
commit 500173d
Showing
5 changed files
with
70 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 - IfUndefined | ||
* @module tutils/types/tests/unit-d/IfUndefined | ||
*/ | ||
|
||
import type TestSubject from '../if-undefined' | ||
|
||
describe('unit-d:types/IfUndefined', () => { | ||
type False = false | ||
type True = true | ||
|
||
it('should equal False if IsUndefined<T> extends false', () => { | ||
expectTypeOf<TestSubject<undefined[], True, False>>().toEqualTypeOf<False>() | ||
}) | ||
|
||
it('should equal True if IsUndefined<T> extends true', () => { | ||
expectTypeOf<TestSubject<undefined, 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 - IsUndefined | ||
* @module tutils/types/tests/unit-d/IsUndefined | ||
*/ | ||
|
||
import type TestSubject from '../is-undefined' | ||
|
||
describe('unit-d:types/IsUndefined', () => { | ||
it('should equal false if T does not extend undefined', () => { | ||
expectTypeOf<TestSubject<null>>().toEqualTypeOf<false>() | ||
}) | ||
|
||
it('should equal true if T extends undefined', () => { | ||
expectTypeOf<TestSubject<undefined>>().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 - IfUndefined | ||
* @module tutils/types/IfUndefined | ||
*/ | ||
|
||
import type IsUndefined from './is-undefined' | ||
|
||
/** | ||
* Conditional type that resolves depending on whether or not `T` extends | ||
* `undefined`. | ||
* | ||
* @see {@linkcode IsUndefined} | ||
* | ||
* @template T - Type to evaluate | ||
* @template True - Type if `T` extends `undefined` | ||
* @template False - Type if `T` does not extend `undefined` | ||
*/ | ||
type IfUndefined<T, True, False> = IsUndefined<T> extends true ? True : False | ||
|
||
export type { IfUndefined 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,13 @@ | ||
/** | ||
* @file Type Definitions - IsUndefined | ||
* @module tutils/types/IsUndefined | ||
*/ | ||
|
||
/** | ||
* Returns a boolean indicating if `T` extends `undefined`. | ||
* | ||
* @template T - Type to evaluate | ||
*/ | ||
type IsUndefined<T> = T extends undefined ? true : false | ||
|
||
export type { IsUndefined as default } |