-
-
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 <[email protected]>
- Loading branch information
1 parent
9ae48c3
commit 1863acc
Showing
5 changed files
with
87 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 - IfObject | ||
* @module tutils/types/tests/unit-d/IfObject | ||
*/ | ||
|
||
import type TestSubject from '../if-object' | ||
|
||
describe('unit-d:types/IfObject', () => { | ||
type False = false | ||
type True = true | ||
|
||
it('should equal False if IsObject<T> extends false', () => { | ||
expectTypeOf<TestSubject<string, True, False>>().toEqualTypeOf<False>() | ||
}) | ||
|
||
it('should equal True if IsObject<T> extends true', () => { | ||
expectTypeOf<TestSubject<object, 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,32 @@ | ||
/** | ||
* @file Type Tests - IsObject | ||
* @module tutils/types/tests/unit-d/IsObject | ||
*/ | ||
|
||
import type Fn from '../fn' | ||
import type TestSubject from '../is-object' | ||
import type ObjectCurly from '../object-curly' | ||
import type Primitive from '../primitive' | ||
|
||
describe('unit-d:types/IsObject', () => { | ||
it('should equal false if [T] does not extend [object]', () => { | ||
expectTypeOf<TestSubject<Primitive>>().toEqualTypeOf<false>() | ||
expectTypeOf<TestSubject<Primitive | object>>().toEqualTypeOf<false>() | ||
}) | ||
|
||
it('should equal false if T is any', () => { | ||
expectTypeOf<TestSubject<any>>().toEqualTypeOf<false>() | ||
}) | ||
|
||
it('should equal false if T is never', () => { | ||
expectTypeOf<TestSubject<never>>().toEqualTypeOf<false>() | ||
}) | ||
|
||
it('should equal true if [T] extends [object]', () => { | ||
expectTypeOf<TestSubject<Fn>>().toEqualTypeOf<true>() | ||
expectTypeOf<TestSubject<ObjectCurly>>().toEqualTypeOf<true>() | ||
expectTypeOf<TestSubject<RegExp>>().toEqualTypeOf<true>() | ||
expectTypeOf<TestSubject<object>>().toEqualTypeOf<true>() | ||
expectTypeOf<TestSubject<readonly string[]>>().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,19 @@ | ||
/** | ||
* @file Type Definitions - IfObject | ||
* @module tutils/types/IfObject | ||
*/ | ||
|
||
import type IsObject from './is-object' | ||
|
||
/** | ||
* Returns a type that indicates if `T` is an `object`. | ||
* | ||
* @see {@linkcode IsObject} | ||
* | ||
* @template T - Type to evaluate | ||
* @template True - Type if `T` is an `object` | ||
* @template False - Type if `T` is not an `object` | ||
*/ | ||
type IfObject<T, True, False> = IsObject<T> extends true ? True : False | ||
|
||
export type { IfObject 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 - IsObject | ||
* @module tutils/types/IsObject | ||
*/ | ||
|
||
import type IfAnyOrNever from './if-any-or-never' | ||
|
||
/** | ||
* Returns a boolean indicating if `T` is an `object`. | ||
* | ||
* @template T - Type to evaluate | ||
*/ | ||
type IsObject<T> = IfAnyOrNever<T, false, [T] extends [object] ? true : false> | ||
|
||
export type { IsObject as default } |