Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 1.01 KB

File metadata and controls

84 lines (58 loc) · 1.01 KB

typelab / conditions / IfTuple

type IfTuple<T, Then, Else> = _IfNotAnyOrNever<T, T extends ReadonlyArray ? number extends T["length"] ? Else : Then : Else, Else>;

Resolves to Then if the type T is a tuple (readonly or writable), otherwise resolves to Else.

Type Parameters

Type Parameter Default type Description

T

The type to be checked.

Then

The type to return if T is a tuple.

Else

never

The type to return if T is not a tuple. Defaults to never.

Returns

Then if T is a tuple, Else otherwise.

Example

type Yes = IfTuple<[string], 'yes', 'no'>; // 'yes'
type No = IfTuple<string[], 'yes', 'no'>; // 'no'
type YesOrNo = IfTuple<[string] | string[], 'yes', 'no'>; // 'yes' | 'no'