Skip to content

isPromise ​

Category
Export size
min 0.06 kB · gzip 0.08 kB

Type guard that checks if a value is a native Promise instance. A thenable that is not a Promise is false.

ts
  import { 
isPromise
} from 'feathers-utils/helpers';

Example ​

ts
import { isPromise } from 'feathers-utils/helpers'

const result = maybeAsync()
if (isPromise(result)) {
  await result
}

Type declaration ​

Show Type Declarations
ts
/**
 * Type guard that checks if a value is a native `Promise` instance. A thenable
 * that is not a `Promise` is `false`.
 *
 * @example
 * ```ts
 *
 *
 * const result = maybeAsync()
 * if (isPromise(result)) {
 *   await result
 * }
 * ```
 *
 * @see https://utils.feathersjs.com/helpers/is-promise.html
 */
export declare function isPromise(p: any): p is Promise<any>
ArgumentTypeDescription
pany

Thenables ​

The check is instanceof Promise, so a custom thenable — an object with a then method that is not a Promise — is false. Every async function returns a native Promise, which covers hooks, predicates and service methods.

Released under the MIT License.