import RSVP, { Promise } from 'rsvp'; /** * AJAX Promise * * Sub-class of RSVP Promise that passes the XHR property on to the * child promise * * @extends RSVP.Promise * @private */ export default class AJAXPromise extends Promise { xhr?: JQueryXHR; // NOTE: Only necessary due to broken definition of RSVP.Promise // https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26640 constructor( executor: ( resolve: (value?: RSVP.Arg) => void, reject: (reason?: any) => void ) => void, label?: string ) { // @ts-ignore super(executor, label); } /** * Overriding `.then` to add XHR to child promise */ then( onFulfilled?: | ((value: T) => TResult1 | PromiseLike) | undefined | null, onRejected?: | ((reason: any) => TResult2 | PromiseLike) | undefined | null, label?: string ): AJAXPromise { const child = super.then(onFulfilled, onRejected, label); (child as AJAXPromise).xhr = this.xhr; return child; } }