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