import ExtendedPromise from './Promise.js'; type SuccessCallback = (this: Scope, value: T) => U; type ErrorCallback = (this: Scope, error: any) => any; /** * Helper to create stable code if a value can be a promise or a non async value. * * @param value value or promise * @param success success callback * @param error error callback * @param scope this binding for the callbacks * @returns always produces a promise * @example * ```ts * // use it as wrapper to get a promise * return when(thing).then((thing)=> doSomethingWithTheThing); * ``` * * @example * ```ts * import when from "apprt-core/when"; * // bind success and error handler from an object * const scope = { * counter : 0, * ok() { * ++this.counter; * }, * error() { * --this.counter; * } * }; * return when(thing, scope.ok, scope.error, scope); * ``` */ declare function when(value?: Value | PromiseLike, success?: SuccessCallback, error?: ErrorCallback, scope?: Scope): ExtendedPromise; /** * Same as the first overload, but without an error callback. */ declare function when(value?: Value | PromiseLike, success?: SuccessCallback, scope?: Scope): ExtendedPromise; export { when as default, when };