Skip to content

Commit

Permalink
feat(types): IfTuple
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed May 13, 2023
1 parent 02d8ba7 commit 59d4e0e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/types/__tests__/if-tuple.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file Type Tests - IfTuple
* @module tutils/types/tests/unit-d/IfTuple
*/

import type TestSubject from '../if-tuple'

describe('unit-d:types/IfTuple', () => {
type False = false
type True = true

it('should equal False if IsTuple<T> extends false', () => {
expectTypeOf<TestSubject<number[], True, False>>().toEqualTypeOf<False>()
})

it('should equal True if IsTuple<T> extends true', () => {
expectTypeOf<TestSubject<[0, 1, 2], True, False>>().toEqualTypeOf<True>()
})
})
22 changes: 22 additions & 0 deletions src/types/if-tuple.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file Type Definitions - IfTuple
* @module tutils/types/IfTuple
*/

import type IsTuple from './is-tuple'

/**
* Conditional type that resolves depending on whether or not `T` is a
* [tuple][1] type.
*
* [1]: https://www.codecademy.com/resources/docs/typescript/tuples
*
* @see {@linkcode IsTuple}
*
* @template T - Type to evaluate
* @template True - Type if `T` is tuple type
* @template False - Type if `T` is not tuple type
*/
type IfTuple<T, True, False> = IsTuple<T> extends true ? True : False

export type { IfTuple as default }
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type { default as IfNumeric } from './if-numeric'
export type { default as IfPrimitive } from './if-primitive'
export type { default as IfString } from './if-string'
export type { default as IfSymbol } from './if-symbol'
export type { default as IfTuple } from './if-tuple'
export type { default as IndexSignature } from './index-signature'
export type { default as IsAny } from './is-any'
export type { default as IsArray } from './is-array'
Expand Down

0 comments on commit 59d4e0e

Please sign in to comment.