Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 989 Bytes

File metadata and controls

84 lines (58 loc) · 989 Bytes

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 Parameters

Type Parameter Default type Description

T

The type to be checked.

Then

The type to return if T is function.

Else

never

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

Returns

Then if T is function, Else otherwise.

Example

type Yes = IfFunction<() => void, 'yes', 'no'>; // 'yes'
type No = IfFunction<string, 'yes', 'no'>; // 'no'
type YesOrNo = IfFunction<(() => void) | string, 'yes', 'no'>; // 'yes' | 'no'