Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 1.12 KB

File metadata and controls

89 lines (61 loc) · 1.12 KB

typelab / conditions / IfTupleReadonly

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

Resolves to Then if the type T is a readonly tuple, 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 readonly tuple.

Else

never

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

Returns

Then if T is a readonly tuple, Else otherwise.

Example

// 'yes'
type Yes = IfTupleReadonly<readonly [string], 'yes', 'no'>;

// 'no'
type No = IfTupleReadonly<[string], 'yes', 'no'>;

// 'yes' | 'no'
type YesOrNo = IfTupleReadonly<readonly [string] | [string], 'yes', 'no'>;