predictype

predictype v0.8.1


predictype / predicates/promises / promiseType

Function: promiseType()

promiseType(source, oper): boolean

Defined in: predicates/promises/promiseType.ts:24

Checks if a value is a Promise or an async function using the specified operation.

Parameters

source

unknown

The value to check.

oper

PromiseTypeOper

The type operation to perform (e.g. ‘is_promise’, ‘is_async_function’).

Returns

boolean

True if the type check is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const p = Promise.resolve(42);
async function foo() {}

promiseType(p, 'is_promise'); // true
promiseType(foo, 'is_async_function'); // true

Remarks

Supported Operators: