typelab / conditions / IfFunction
type IfFunction<T, Then, Else> = _IfNotAnyOrNever<T, T extends Fn ? Then : Else, Else>;Resolves to Then if the type T is a function, 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 function, Else otherwise.
type Yes = IfFunction<() => void, 'yes', 'no'>; // 'yes'
type No = IfFunction<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfFunction<(() => void) | string, 'yes', 'no'>; // 'yes' | 'no'