UNPKG

@xylabs/promise

Version:

Base functionality used throughout XY Labs TypeScript/JavaScript libraries

26 lines (19 loc) 491 B
import type { TypedValue } from '@xylabs/typeof' export interface PromiseType { then: () => unknown } export type AnyNonPromise = Exclude<TypedValue, Promise<unknown>> export const isPromise = (value: unknown): value is Promise<unknown> => { if (typeof value === 'object' && !Array.isArray(value)) { return typeof (value as PromiseType).then === 'function' } return false } // type test /* const x = Promise.resolve() const f = (x: AnyNonPromise) => { return x } f(x) */