Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 991 Bytes

File metadata and controls

84 lines (58 loc) · 991 Bytes

typelab / conditions / IfBoolean

type IfBoolean<T, Then, Else> = _IfNotAnyOrNever<T, T extends boolean ? Then : Else, Else>;

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

Else

never

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

Returns

Then if T is a boolean, Else otherwise.

Example

type Yes = IfBoolean<boolean, 'yes', 'no'>; // 'yes'
type No = IfBoolean<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfBoolean<boolean | string, 'yes', 'no'>; // 'yes' | 'no'