/** A promise of a value or the value itself. */ export type Promised = T | Promise; /** A function which returns a promised value. */ export type Promiser = () => Promised; /** A promised value or a function which returns a promised value. */ export type DynamicPromise = Promised | Promiser; /** Checks if data is a promise. */ export const isPromise = (promise: Promised): promise is Promise => promise instanceof Promise; /** Convert a dynamic promise to a promise. */ export const resolveDynamicPromise = async (dynamic: DynamicPromise): Promise => { if (typeof dynamic === 'function') return await (dynamic as Promiser)(); return await dynamic; };