Merge pull request #26420 from leonard-thieu/jquery/bluebird-global

[jquery] Fix compatibility issue with `@types/bluebird-global`.
This commit is contained in:
Nathan Shively-Sanders
2018-06-18 14:14:22 -07:00
committed by GitHub
4 changed files with 33 additions and 8 deletions
+23 -3
View File
@@ -37,8 +37,6 @@ declare const $: JQueryStatic;
// Used by JQuery.Event
type _Event = Event;
// Used by JQuery.Promise3 and JQuery.Promise
type _Promise<T> = Promise<T>;
interface JQueryStatic<TElement = HTMLElement> {
/**
@@ -6557,6 +6555,28 @@ declare namespace JQuery {
*/
interface Thenable<T> extends PromiseLike<T> { }
// 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<T> {
/**
* 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<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null): JQuery._Promise<TResult1 | TResult2>;
/**
* 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<TResult = never>(onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | null): JQuery._Promise<T | TResult>;
}
// 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<TR, TJ, TN,
UR, UJ, UN,
VR, VJ, VN,
SR, SJ, SN> extends _Promise<TR>, PromiseLike<TR> {
SR, SJ, SN> extends JQuery._Promise<TR>, PromiseLike<TR> {
/**
* Add handlers to be called when the Deferred object is either resolved or rejected.
*
+4 -4
View File
@@ -7058,7 +7058,7 @@ function JQuery_jqXHR() {
}
}
function compatibleWithPromise(): Promise<any> {
function compatibleWithPromise(): JQuery._Promise<any> {
return p;
}
@@ -7480,7 +7480,7 @@ function JQuery_Promise3() {
return s;
}
function compatibleWithPromise(): Promise<any> {
function compatibleWithPromise(): JQuery._Promise<any> {
return p;
}
@@ -7624,7 +7624,7 @@ function JQuery_Promise2(p: JQuery.Promise2<string, Error, number, JQuery, strin
return s;
}
function compatibleWithPromise(): Promise<any> {
function compatibleWithPromise(): JQuery._Promise<any> {
return p;
}
@@ -7745,7 +7745,7 @@ function JQuery_Promise(p: JQuery.Promise<string, Error, number>) {
return s;
}
function compatibleWithPromise(): Promise<any> {
function compatibleWithPromise(): JQuery._Promise<any> {
return p;
}
}
@@ -0,0 +1,4 @@
/// <reference types="bluebird-global" />
// Pulls in bluebird-global to test compatibility.
// Fixes https://github.com/DefinitelyTyped/DefinitelyTyped/issues/26328.
+2 -1
View File
@@ -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"
]
}
}