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 Parameter | Default type | Description |
|---|---|---|
|
|
‐ |
The type to be checked. |
|
|
‐ |
The type to return if |
|
|
|
The type to return if |
Then if T is a boolean, Else otherwise.
type Yes = IfBoolean<boolean, 'yes', 'no'>; // 'yes'
type No = IfBoolean<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfBoolean<boolean | string, 'yes', 'no'>; // 'yes' | 'no'