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