From 83311151c9595c1c77394f615d0f5d0543e55cc0 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sun, 10 Jun 2018 12:21:09 -0400 Subject: [PATCH 1/2] [jquery] Fix compatibility issue with `@types/bluebird-global`. `@types/jquery` used the global Promise interface to indicate compatibility with other Promise implementations. `@types/bluebird-global` modifies the global Promise interface making it unsafe to use. To remedy this, a private copy of the global Promise interface is introduced. --- types/jquery/index.d.ts | 26 +++++++++++++++++++--- types/jquery/jquery-tests.ts | 8 +++---- types/jquery/test/bluebird-global-tests.ts | 4 ++++ types/jquery/tsconfig.json | 3 ++- types/jquery/tslint.json | 1 + 5 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 types/jquery/test/bluebird-global-tests.ts diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index b0838f9a8d..72dff2b418 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 { /** @@ -6525,6 +6523,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. @@ -6550,7 +6570,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 47a85b80d2..2d0707bbe6 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -6857,7 +6857,7 @@ function JQuery_jqXHR() { } } - function compatibleWithPromise(): Promise { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7279,7 +7279,7 @@ function JQuery_Promise3() { return s; } - function compatibleWithPromise(): Promise { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7423,7 +7423,7 @@ function JQuery_Promise2(p: JQuery.Promise2 { + function compatibleWithPromise(): JQuery._Promise { return p; } @@ -7544,7 +7544,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 +} diff --git a/types/jquery/tslint.json b/types/jquery/tslint.json index deae83dc66..d1d7bd0a0a 100644 --- a/types/jquery/tslint.json +++ b/types/jquery/tslint.json @@ -14,6 +14,7 @@ "no-empty-interface": false, "no-misused-new": false, "no-object-literal-type-assertion": false, + "no-redundant-jsdoc-2": false, "no-unnecessary-generics": false, "no-unnecessary-qualifier": false, "no-unnecessary-type-assertion": false, From 25062452103575f9c4df7e7da42c84f5d2ae73aa Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Sat, 16 Jun 2018 14:55:01 -0400 Subject: [PATCH 2/2] [jquery] Fix error due to breaking change in TypeScript lib declarations. --- types/jquery/index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 72dff2b418..ae9f6f93d5 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -6361,7 +6361,9 @@ declare namespace JQuery { }; // Writable properties on XMLHttpRequest - interface XHRFields extends Partial> { } + interface XHRFields extends Partial> { + msCaching?: string; + } } interface Transport {