diff --git a/src/types/__tests__/if-object.spec-d.ts b/src/types/__tests__/if-object.spec-d.ts new file mode 100644 index 00000000..5ba4ebf0 --- /dev/null +++ b/src/types/__tests__/if-object.spec-d.ts @@ -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 extends false', () => { + expectTypeOf>().toEqualTypeOf() + }) + + it('should equal True if IsObject extends true', () => { + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/is-object.spec-d.ts b/src/types/__tests__/is-object.spec-d.ts new file mode 100644 index 00000000..3f1654ac --- /dev/null +++ b/src/types/__tests__/is-object.spec-d.ts @@ -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>().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf() + }) + + it('should equal false if T is any', () => { + expectTypeOf>().toEqualTypeOf() + }) + + it('should equal false if T is never', () => { + expectTypeOf>().toEqualTypeOf() + }) + + it('should equal true if [T] extends [object]', () => { + expectTypeOf>().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf() + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/if-object.ts b/src/types/if-object.ts new file mode 100644 index 00000000..e8df2e9e --- /dev/null +++ b/src/types/if-object.ts @@ -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 = IsObject extends true ? True : False + +export type { IfObject as default } diff --git a/src/types/index.ts b/src/types/index.ts index af4412b9..ac3be97c 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -44,6 +44,7 @@ export type { default as IfNil } from './if-nil' export type { default as IfNull } from './if-null' export type { default as IfNumber } from './if-number' export type { default as IfNumeric } from './if-numeric' +export type { default as IfObject } from './if-object' export type { default as IfPrimitive } from './if-primitive' export type { default as IfString } from './if-string' export type { default as IfSymbol } from './if-symbol' @@ -68,6 +69,7 @@ export type { default as IsNil } from './is-nil' export type { default as IsNull } from './is-null' export type { default as IsNumber } from './is-number' export type { default as IsNumeric } from './is-numeric' +export type { default as IsObject } from './is-object' export type { default as IsPrimitive } from './is-primitive' export type { default as IsString } from './is-string' export type { default as IsSymbol } from './is-symbol' diff --git a/src/types/is-object.ts b/src/types/is-object.ts new file mode 100644 index 00000000..49d7365f --- /dev/null +++ b/src/types/is-object.ts @@ -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 = IfAnyOrNever + +export type { IsObject as default }