import { type EventsDefinition, type TypedEmitter } from './events'; /** * Extends `Promise` with a polymorphic `this` type to accomodate arbitrary * `Promise` API extensions. */ interface ExtendedPromise extends Promise { then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): ExtendedPromise & this; catch(onrejected?: ((reason: any) => TResult | PromiseLike) | undefined | null): ExtendedPromise & this; finally(onfinally?: (() => void) | undefined | null): ExtendedPromise & this; } /** * A `Promise` and `EventEmitter` all in one! */ export type PromiEvent = ExtendedPromise & TypedEmitter : TEvents & DefaultEvents>; /** * Default events attached to every `PromiEvent`. */ type DefaultEvents = { done: (result: TResult) => void; error: (reason: any) => void; settled: () => void; }; /** * A `Promise` executor with can be optionally asynchronous. */ type AsyncPromiseExecutor = (resolve: (value: TResult | PromiseLike) => void, reject: (reason?: any) => void) => void | Promise; /** * Returns `true` if the given `value` is a `PromiEvent`. */ export declare function isPromiEvent(value: any): value is PromiEvent; /** * Create a native JavaScript `Promise` overloaded with strongly-typed methods * from `EventEmitter`. */ export declare function createPromiEvent(executor: AsyncPromiseExecutor): PromiEvent : TEvents & DefaultEvents>; /** * Creates a `Promise` with an **async executor** that automatically catches * errors occurring within the executor. Nesting promises in this way is usually * deemed an _anti-pattern_, but it's useful and clean when promisifying the * event-based code that's inherent to JSON RPC. * * So, here we solve the issue of nested promises by ensuring that no errors * mistakenly go unhandled! */ export declare function createPromise(executor: AsyncPromiseExecutor): Promise; export {};