/** * Progress events are emitted during long running operations */ export interface ProgressEvent { /** * The event type */ type: T /** * Context-specific event information */ detail: D } /** * An implementation of the ProgressEvent interface, this is essentially * a typed `CustomEvent` with a `type` property that lets us disambiguate * events passed to `progress` callbacks. */ export class CustomProgressEvent extends Event implements ProgressEvent { public type: T public detail: D constructor (type: T, detail?: D) { super(type) this.type = type // @ts-expect-error detail may be undefined this.detail = detail } } /** * Define an `onProgress` callback that can be invoked with `ProgressEvent`s * * @example * * ```typescript * type MyOperationProgressEvents = * ProgressEvent<'operation:start'> | * ProgressEvent<'operation:success', Result> | * ProgressEvent<'operation:error', Error> * * export interface MyOperationOptions extends ProgressOptions { * // define options here * } * ``` */ export interface ProgressOptions { onProgress?: (evt: Event) => void }