Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 1.05 KB

File metadata and controls

84 lines (58 loc) · 1.05 KB

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 Parameters

Type Parameter Default type Description

T

The type to be checked.

Then

The type to return if T is async function.

Else

never

The type to return if T is not async function. Defaults to never.

Returns

Then if T is async function, Else otherwise.

Example

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'