[jquery] Change Promise2 to extend from Promise3.

This commit is contained in:
Leonard Thieu
2017-06-27 17:57:35 -04:00
parent d2a6dc64c0
commit d03b2b9ad5
2 changed files with 18 additions and 318 deletions
+3 -292
View File
@@ -4591,10 +4591,6 @@ declare namespace JQuery {
(t: T, u: U, v: V): void;
}
interface Callback2<T, U> {
(t: T, u: U): void;
}
interface Callback<T> {
(...args: T[]): void;
}
@@ -5059,294 +5055,9 @@ declare namespace JQuery {
* @see {@link http://api.jquery.com/Types/#Promise}
*/
interface Promise2<TR, TJ, TN,
UR, UJ = any, UN = any> {
/**
* Add handlers to be called when the Deferred object is either resolved or rejected.
*
* @param alwaysCallback A function, or array of functions, that is called when the Deferred is resolved or rejected.
* @param alwaysCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected.
* @see {@link https://api.jquery.com/deferred.always/}
* @since 1.6
*/
always(alwaysCallback: TypeOrArray<Deferred.Callback2<TR | TJ, UR | UJ>>,
...alwaysCallbacks: Array<TypeOrArray<Deferred.Callback2<TR | TJ, UR | UJ>>>): this;
/**
* Add handlers to be called when the Deferred object is resolved.
*
* @param doneCallback A function, or array of functions, that are called when the Deferred is resolved.
* @param doneCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is resolved.
* @see {@link https://api.jquery.com/deferred.done/}
* @since 1.5
*/
done(doneCallback: TypeOrArray<Deferred.Callback2<TR, UR>>,
...doneCallbacks: Array<TypeOrArray<Deferred.Callback2<TR, UR>>>): this;
/**
* Add handlers to be called when the Deferred object is rejected.
*
* @param failCallback A function, or array of functions, that are called when the Deferred is rejected.
* @param failCallbacks Optional additional functions, or arrays of functions, that are called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.fail/}
* @since 1.5
*/
fail(failCallback: TypeOrArray<Deferred.Callback2<TJ, UJ>>,
...failCallbacks: Array<TypeOrArray<Deferred.Callback2<TJ, UJ>>>): this;
/**
* Add handlers to be called when the Deferred object generates progress notifications.
*
* @param progressCallback A function, or array of functions, to be called when the Deferred generates progress notifications.
* @param progressCallbacks Optional additional functions, or arrays of functions, to be called when the Deferred generates
* progress notifications.
* @see {@link https://api.jquery.com/deferred.progress/}
* @since 1.7
*/
progress(progressCallback: TypeOrArray<Deferred.Callback2<TN, UN>>,
...progressCallbacks: Array<TypeOrArray<Deferred.Callback2<TN, UN>>>): this;
/**
* Return a Deferred's Promise object.
*
* @param target Object onto which the promise methods have to be attached
* @see {@link https://api.jquery.com/deferred.promise/}
* @since 1.5
*/
promise<TTarget extends object>(target: TTarget): this & TTarget;
/**
* Return a Deferred's Promise object.
*
* @see {@link https://api.jquery.com/deferred.promise/}
* @since 1.5
*/
promise(): this;
/**
* Determine the current state of a Deferred object.
*
* @see {@link https://api.jquery.com/deferred.state/}
* @since 1.7
*/
state(): 'pending' | 'resolved' | 'rejected';
/**
* Add handlers to be called when the Deferred object is rejected.
*
* @param failFilter A function that is called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.catch/}
* @since 3.0
*/
catch<AR, AJ = never, AN = TN,
BR = never, BJ = never, BN = UN>
(failFilter: (t: TJ, u: UJ) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AR> | AR): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR1, AR2, AR3 = never, AJ1 = never, AJ2 = never, AJ3 = never, AN1 = AN3, AN2 = AN3, AN3 = TN,
BR1 = never, BR2 = never, BR3 = never, BJ1 = never, BJ2 = never, BJ3 = never, BN1 = BN3, BN2 = BN3, BN3 = never>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: (t: TJ, u: UJ) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AR2> | AR2,
progressFilter: (t: TN, u: UN) => Promise2<AR3, AJ3, AN3, BR3, BJ3, BN3> | Thenable<AN3> | AN3): Promise2<AR1 | AR2 | AR3, AJ1 | AJ2 | AJ3, AN1 | AN2 | AN3,
BR1 | BR2 | BR3, BJ1 | BJ2 | BJ3, BN1 | BN2 | BN3>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR1, AR2 = never, AJ1 = never, AJ2 = never, AN1 = AN2, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = BN2, BN2 = UN>
(doneFilter: null,
failFilter: (t: TJ, u: UJ) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
progressFilter: (t: TN, u: UN) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AN1> | AN1): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR1, AR2 = never, AJ1 = never, AJ2 = never, AN1 = AN2, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = BN2, BN2 = UN>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: null,
progressFilter: (t: TN, u: UN) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AN1> | AN1): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR = TJ, AJ = TJ, AN = TN,
BR = UJ, BJ = UJ, BN = never>
(doneFilter: null,
failFilter: null,
progressFilter: (t: TN, u: UN) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AN> | AN): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR1, AR2, AJ1 = never, AJ2 = never, AN1 = TN, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = UN, BN2 = UN>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: (t: TJ, u: UJ) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AR2> | AR2,
progressFilter?: null): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR, AJ = never, AN = TN,
BR = never, BJ = never, BN = UN>
(doneFilter: null,
failFilter: (t: TJ, u: UJ) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AR> | AR,
progressFilter?: null): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Utility method to filter and/or chain Deferreds.
*
* @param doneFilter An optional function that is called when the Deferred is resolved.
* @see {@link https://api.jquery.com/deferred.pipe/}
* @since 1.6
* @since 1.7
* @deprecated 1.8
*/
pipe<AR, AJ = TJ, AN = TN,
BR = never, BJ = UJ, BN = UN>
(doneFilter: ((t: TR, u: UR) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AR> | AR) | null,
failFilter?: null,
progressFilter?: null): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR1, AR2, AR3 = never, AJ1 = never, AJ2 = never, AJ3 = never, AN1 = AN3, AN2 = AN3, AN3 = TN,
BR1 = never, BR2 = never, BR3 = never, BJ1 = never, BJ2 = never, BJ3 = never, BN1 = BN3, BN2 = BN3, BN3 = never>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: (t: TJ, u: UJ) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AR2> | AR2,
progressFilter: (t: TN, u: UN) => Promise2<AR3, AJ3, AN3, BR3, BJ3, BN3> | Thenable<AN3> | AN3): Promise2<AR1 | AR2 | AR3, AJ1 | AJ2 | AJ3, AN1 | AN2 | AN3,
BR1 | BR2 | BR3, BJ1 | BJ2 | BJ3, BN1 | BN2 | BN3>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR1, AR2 = never, AJ1 = never, AJ2 = never, AN1 = AN2, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = BN2, BN2 = UN>
(doneFilter: null,
failFilter: (t: TJ, u: UJ) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
progressFilter: (t: TN, u: UN) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AN1> | AN1): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR1, AR2 = never, AJ1 = never, AJ2 = never, AN1 = AN2, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = BN2, BN2 = UN>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: null,
progressFilter: (t: TN, u: UN) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AN1> | AN1): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @param progressFilter An optional function that is called when progress notifications are sent to the Deferred.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR = TJ, AJ = TJ, AN = TN,
BR = UJ, BJ = UJ, BN = never>
(doneFilter: null,
failFilter: null,
progressFilter: (t: TN, u: UN) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AN> | AN): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR1, AR2, AJ1 = never, AJ2 = never, AN1 = TN, AN2 = TN,
BR1 = never, BR2 = never, BJ1 = never, BJ2 = never, BN1 = UN, BN2 = UN>
(doneFilter: (t: TR, u: UR) => Promise2<AR1, AJ1, AN1, BR1, BJ1, BN1> | Thenable<AR1> | AR1,
failFilter: (t: TJ, u: UJ) => Promise2<AR2, AJ2, AN2, BR2, BJ2, BN2> | Thenable<AR2> | AR2,
progressFilter?: null): Promise2<AR1 | AR2, AJ1 | AJ2, AN1 | AN2,
BR1 | BR2, BJ1 | BJ2, BN1 | BN2>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @param failFilter An optional function that is called when the Deferred is rejected.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR, AJ = never, AN = TN,
BR = never, BJ = never, BN = UN>
(doneFilter: null,
failFilter: (t: TJ, u: UJ) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AR> | AR,
progressFilter?: null): Promise2<AR, AJ, AN, BR, BJ, BN>;
/**
* Add handlers to be called when the Deferred object is resolved, rejected, or still in progress.
*
* @param doneFilter A function that is called when the Deferred is resolved.
* @see {@link https://api.jquery.com/deferred.then/}
* @since 1.8
*/
then<AR, AJ = TJ, AN = TN,
BR = never, BJ = UJ, BN = UN>
(doneFilter: ((t: TR, u: UR) => Promise2<AR, AJ, AN, BR, BJ, BN> | Thenable<AR> | AR) | null,
failFilter?: null,
progressFilter?: null): Promise2<AR, AJ, AN, BR, BJ, BN>;
}
UR, UJ, UN> extends Promise3<TR, TJ, TN,
UR, UJ, UN,
never, never, never> { }
/**
* This object provides a subset of the methods of the Deferred object (then, done, fail, always,
+15 -26
View File
@@ -4579,9 +4579,9 @@ function JQueryStatic() {
}
function Promise2() {
const t = $.Deferred() as JQuery.Promise2<string, Error, number, boolean>;
const u = $.Deferred() as JQuery.Promise2<string, Error, number, boolean>;
const v = $.Deferred() as JQuery.Promise2<string, Error, number, boolean>;
const t = $.Deferred() as JQuery.Promise2<string, Error, number, boolean, any, any>;
const u = $.Deferred() as JQuery.Promise2<string, Error, number, boolean, any, any>;
const v = $.Deferred() as JQuery.Promise2<string, Error, number, boolean, any, any>;
// 3 parameters
{
@@ -5364,11 +5364,6 @@ function jqXHR() {
errorThrown;
});
}
function then_returnType() {
// $ExpectType Promise3<void, jqXHR<any>, never, never, ErrorTextStatus, never, never, string, never>
$.ajax('/echo/json').then(() => { });
}
}
function Promise3() {
@@ -5800,7 +5795,7 @@ function Promise2(p: JQuery.Promise2<string, Error, number, JQuery, string, bool
}, (a, b) => {
a; // $ExpectType Error
b; // $ExpectType string
});
}, null);
p.then((a, b) => {
a; // $ExpectType string
@@ -5808,11 +5803,6 @@ function Promise2(p: JQuery.Promise2<string, Error, number, JQuery, string, bool
}, (a, b) => {
a; // $ExpectType Error
b; // $ExpectType string
}, null);
p.then(null, (a, b) => {
a; // $ExpectType Error
b; // $ExpectType string
});
p.then(null, (a, b) => {
@@ -5820,26 +5810,25 @@ function Promise2(p: JQuery.Promise2<string, Error, number, JQuery, string, bool
b; // $ExpectType string
}, null);
p.then((a, b) => {
a; // $ExpectType string
b; // $ExpectType JQuery<HTMLElement>
p.then(null, (a, b) => {
a; // $ExpectType Error
b; // $ExpectType string
});
p.then((a, b) => {
a; // $ExpectType string
b; // $ExpectType JQuery<HTMLElement>
}, null);
p.then((a, b) => {
a; // $ExpectType string
b; // $ExpectType JQuery<HTMLElement>
}, null, null);
p.then(null);
p.then((a, b) => {
a; // $ExpectType string
b; // $ExpectType JQuery<HTMLElement>
}, null);
p.then(null, null);
p.then(null, null, null);
p.then((a, b) => {
a; // $ExpectType string
b; // $ExpectType JQuery<HTMLElement>
});
function doneFilter() {
p.then(() => {