diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 79525510e9..14e1e06501 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -37,8 +37,6 @@ declare const $: JQueryStatic; // Used by JQuery.Event type _Event = Event; -// Used by JQuery.Promise3 and JQuery.Promise -type _Promise = Promise; interface JQueryStatic { /** @@ -6557,6 +6555,28 @@ declare namespace JQuery { */ interface Thenable extends PromiseLike { } + // NOTE: This is a private copy of the global Promise interface. It is used by JQuery.PromiseBase to indicate compatibility with other Promise implementations. + // The global Promise interface cannot be used directly as it may be modified, as in the case of @types/bluebird-global. + /** + * Represents the completion of an asynchronous operation + */ + interface _Promise { + /** + * Attaches callbacks for the resolution and/or rejection of the Promise. + * @param onfulfilled The callback to execute when the Promise is resolved. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of which ever callback is executed. + */ + then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | null, + onrejected?: ((reason: any) => TResult2 | PromiseLike) | null): JQuery._Promise; + /** + * Attaches a callback for only the rejection of the Promise. + * @param onrejected The callback to execute when the Promise is rejected. + * @returns A Promise for the completion of the callback. + */ + catch(onrejected?: ((reason: any) => TResult | PromiseLike) | null): JQuery._Promise; + } + // Type parameter guide // -------------------- // Each type parameter represents a parameter in one of the three possible callbacks. @@ -6582,7 +6602,7 @@ declare namespace JQuery { interface PromiseBase extends _Promise, PromiseLike { + SR, SJ, SN> extends JQuery._Promise, PromiseLike { /** * Add handlers to be called when the Deferred object is either resolved or rejected. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index a8b47cddd1..f0d1ce5ef8 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -7058,7 +7058,7 @@ function JQuery_jqXHR() { } } - function compatibleWithPromise(): Promise { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7480,7 +7480,7 @@ function JQuery_Promise3() { return s; } - function compatibleWithPromise(): Promise { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7624,7 +7624,7 @@ function JQuery_Promise2(p: JQuery.Promise2 { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7745,7 +7745,7 @@ function JQuery_Promise(p: JQuery.Promise) { return s; } - function compatibleWithPromise(): Promise { + function compatibleWithPromise(): JQuery._Promise { return p; } } diff --git a/types/jquery/test/bluebird-global-tests.ts b/types/jquery/test/bluebird-global-tests.ts new file mode 100644 index 0000000000..3b7f58e9cd --- /dev/null +++ b/types/jquery/test/bluebird-global-tests.ts @@ -0,0 +1,4 @@ +/// + +// Pulls in bluebird-global to test compatibility. +// Fixes https://github.com/DefinitelyTyped/DefinitelyTyped/issues/26328. diff --git a/types/jquery/tsconfig.json b/types/jquery/tsconfig.json index e481dc63c6..40a0bc76d4 100644 --- a/types/jquery/tsconfig.json +++ b/types/jquery/tsconfig.json @@ -21,6 +21,7 @@ "files": [ "index.d.ts", "jquery-tests.ts", + "test/bluebird-global-tests.ts", "test/example-tests.ts", "test/longdesc-tests.ts", "test/learn-tests.ts", @@ -29,4 +30,4 @@ "test/jquery-slim-no-window-module-tests.ts", "test/jquery-slim-window-module-tests.ts" ] -} \ No newline at end of file +}