Skip to content

Latest commit

 

History

History
89 lines (61 loc) · 1.08 KB

File metadata and controls

89 lines (61 loc) · 1.08 KB

typelab / conditions / IfArrayReadonly

type IfArrayReadonly<T, Then, Else> = _IfNotAnyOrNever<T, T extends ReadonlyArray ? T extends WritableArray ? Else : Then : Else, Else>;

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

Else

never

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

Returns

Then if T is a readonly array, Else otherwise.

Example

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

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

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