From c735b73233baab5e9ff3b0e30ca5c644c9aec0b4 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Tue, 27 Jun 2017 18:16:04 -0400 Subject: [PATCH] [jquery] Fix Promise and Deferred. Fix when() ordering. --- types/jquery/index.d.ts | 851 +++++++++++++---------------------- types/jquery/jquery-tests.ts | 39 +- 2 files changed, 319 insertions(+), 571 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 862cd57e4a..658a463c83 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -3267,20 +3267,6 @@ interface JQueryStatic { * @since 1.12-2.2 */ uniqueSort(array: T[]): T[]; - /** - * Provides a way to execute callback functions based on zero or more Thenable objects, usually - * Deferred objects that represent asynchronous events. - * - * @see {@link https://api.jquery.com/jQuery.when/} - * @since 1.5 - */ - when - (deferredT: JQuery.Promise | JQuery.Thenable | TR1, - deferredU: JQuery.Promise | JQuery.Thenable | UR1, - deferredV: JQuery.Promise | JQuery.Thenable | VR1): JQuery.Promise3; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3312,11 +3298,13 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.when/} * @since 1.5 */ - when + when (deferredT: JQuery.Promise | JQuery.Thenable | TR1, - deferredU: JQuery.Promise | JQuery.Thenable | UR1): JQuery.Promise2; + deferredU: JQuery.Promise | JQuery.Thenable | UR1, + deferredV: JQuery.Promise | JQuery.Thenable | VR1): JQuery.Promise3; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3342,7 +3330,11 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.when/} * @since 1.5 */ - when(deferred: JQuery.Promise | JQuery.Thenable | TR1): JQuery.Promise; + when + (deferredT: JQuery.Promise | JQuery.Thenable | TR1, + deferredU: JQuery.Promise | JQuery.Thenable | UR1): JQuery.Promise2; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -3355,6 +3347,14 @@ interface JQueryStatic { TR3 = never, TJ3 = never> (deferredT: JQuery.Promise3 | JQuery.Promise2): JQuery.Promise3; + /** + * Provides a way to execute callback functions based on zero or more Thenable objects, usually + * Deferred objects that represent asynchronous events. + * + * @see {@link https://api.jquery.com/jQuery.when/} + * @since 1.5 + */ + when(deferred: JQuery.Promise | JQuery.Thenable | TR1): JQuery.Promise; /** * Provides a way to execute callback functions based on zero or more Thenable objects, usually * Deferred objects that represent asynchronous events. @@ -4271,351 +4271,6 @@ declare namespace JQuery { */ interface Thenable extends PromiseLike { } - interface DeferredStatic { - // https://jquery.com/upgrade-guide/3.0/#callback-exit - exceptionHook: any; - (beforeStart?: (this: JQuery.Deferred, deferred: JQuery.Deferred) => void): JQuery.Deferred; - } - - interface Deferred { - /** - * 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>, - ...alwaysCallbacks: Array>>): 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>, - ...doneCallbacks: Array>>): 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>, - ...failCallbacks: Array>>): 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>, - ...progressCallbacks: Array>>): 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(target: TTarget): JQuery.Promise & TTarget; - /** - * Return a Deferred's Promise object. - * - * @see {@link https://api.jquery.com/deferred.promise/} - * @since 1.5 - */ - promise(): JQuery.Promise; - /** - * 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(failFilter: (...reasons: TJ[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; - - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN3): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR1, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; - - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN3): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR1, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; - - /** - * Call the progressCallbacks on a Deferred object with the given args. - * - * @param args Optional arguments that are passed to the progressCallbacks. - * @see {@link https://api.jquery.com/deferred.notify/} - * @since 1.7 - */ - notify(...args: TN[]): this; - /** - * Call the progressCallbacks on a Deferred object with the given context and args. - * - * @param context Context passed to the progressCallbacks as the this object. - * @param args An optional array of arguments that are passed to the progressCallbacks. - * @see {@link https://api.jquery.com/deferred.notifyWith/} - * @since 1.7 - */ - notifyWith(context: object, args?: ArrayLike): this; - /** - * Reject a Deferred object and call any failCallbacks with the given args. - * - * @param args Optional arguments that are passed to the failCallbacks. - * @see {@link https://api.jquery.com/deferred.reject/} - * @since 1.5 - */ - reject(...args: TJ[]): this; - /** - * Reject a Deferred object and call any failCallbacks with the given context and args. - * - * @param context Context passed to the failCallbacks as the this object. - * @param args An optional array of arguments that are passed to the failCallbacks. - * @see {@link https://api.jquery.com/deferred.rejectWith/} - * @since 1.5 - */ - rejectWith(context: object, args?: ArrayLike): this; - /** - * Resolve a Deferred object and call any doneCallbacks with the given args. - * - * @param args Optional arguments that are passed to the doneCallbacks. - * @see {@link https://api.jquery.com/deferred.resolve/} - * @since 1.5 - */ - resolve(...args: TR[]): this; - /** - * Resolve a Deferred object and call any doneCallbacks with the given context and args. - * - * @param context Context passed to the doneCallbacks as the this object. - * @param args An optional array of arguments that are passed to the doneCallbacks. - * @see {@link https://api.jquery.com/deferred.resolveWith/} - * @since 1.5 - */ - resolveWith(context: object, args?: ArrayLike): this; - } - - namespace Deferred { - interface Callback3 { - (t: T, u: U, v: V): void; - } - - interface Callback { - (...args: T[]): void; - } - - /** - * @deprecated - */ - interface DoneCallback extends Callback { } - - /** - * @deprecated - */ - interface FailCallback extends Callback { } - - /** - * @deprecated - */ - interface AlwaysCallback extends Callback { } - - /** - * @deprecated - */ - interface ProgressCallback extends Callback { } - } - // Type parameter guide // -------------------- // Each type parameter represents a parameter in one of the three possible callbacks. @@ -5114,14 +4769,14 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.promise/} * @since 1.5 */ - promise(target: TTarget): JQuery.Promise & TTarget; + promise(target: TTarget): JQuery.Promise & TTarget; /** * Return a Deferred's Promise object. * * @see {@link https://api.jquery.com/deferred.promise/} * @since 1.5 */ - promise(): JQuery.Promise; + promise(): JQuery.Promise; /** * Determine the current state of a Deferred object. * @@ -5130,6 +4785,207 @@ declare namespace JQuery { */ state(): 'pending' | 'resolved' | 'rejected'; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: (...t: TR[]) => Promise | Thenable | AJF, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: null, + failFilter: (...t: TR[]) => Promise | Thenable | AJF, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: null, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: null, + failFilter: (...t: TR[]) => Promise | Thenable | AJF, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: (...t: TJ[]) => Promise | Thenable | AJF, + progressFilter?: null): Promise; + /** + * 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 + (doneFilter: null, + failFilter: (...t: TJ[]) => Promise | Thenable | AJF, + progressFilter?: null): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise; + + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: (...t: TR[]) => Promise | Thenable | ARF, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: null, + failFilter: (...t: TR[]) => Promise | Thenable | ARF, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: null, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: null, + failFilter: null, + progressFilter: (...t: TN[]) => Promise | Thenable | ANP): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter: (...t: TJ[]) => Promise | Thenable | ARF, + progressFilter?: null): Promise; + /** + * 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 + (doneFilter: null, + failFilter: (...t: TJ[]) => Promise | Thenable | ARF, + progressFilter?: null): Promise; + /** + * 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 + (doneFilter: (...t: TR[]) => Promise | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise; + /** * Add handlers to be called when the Deferred object is rejected. * @@ -5137,197 +4993,98 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.catch/} * @since 3.0 */ - catch(failFilter: (...reasons: TJ[]) => JQuery.Promise | Thenable | AR): JQuery.Promise; + catch + (failFilter: (...t: TJ[]) => Promise | Thenable | ARF): Promise; + } + + interface DeferredStatic { + // https://jquery.com/upgrade-guide/3.0/#callback-exit + exceptionHook: any; + (beforeStart?: (this: JQuery.Deferred, deferred: JQuery.Deferred) => void): JQuery.Deferred; + } + + interface Deferred extends JQuery.Promise { + /** + * Call the progressCallbacks on a Deferred object with the given args. + * + * @param args Optional arguments that are passed to the progressCallbacks. + * @see {@link https://api.jquery.com/deferred.notify/} + * @since 1.7 + */ + notify(...args: TN[]): this; + /** + * Call the progressCallbacks on a Deferred object with the given context and args. + * + * @param context Context passed to the progressCallbacks as the this object. + * @param args An optional array of arguments that are passed to the progressCallbacks. + * @see {@link https://api.jquery.com/deferred.notifyWith/} + * @since 1.7 + */ + notifyWith(context: object, args?: ArrayLike): this; + /** + * Reject a Deferred object and call any failCallbacks with the given args. + * + * @param args Optional arguments that are passed to the failCallbacks. + * @see {@link https://api.jquery.com/deferred.reject/} + * @since 1.5 + */ + reject(...args: TJ[]): this; + /** + * Reject a Deferred object and call any failCallbacks with the given context and args. + * + * @param context Context passed to the failCallbacks as the this object. + * @param args An optional array of arguments that are passed to the failCallbacks. + * @see {@link https://api.jquery.com/deferred.rejectWith/} + * @since 1.5 + */ + rejectWith(context: object, args?: ArrayLike): this; + /** + * Resolve a Deferred object and call any doneCallbacks with the given args. + * + * @param args Optional arguments that are passed to the doneCallbacks. + * @see {@link https://api.jquery.com/deferred.resolve/} + * @since 1.5 + */ + resolve(...args: TR[]): this; + /** + * Resolve a Deferred object and call any doneCallbacks with the given context and args. + * + * @param context Context passed to the doneCallbacks as the this object. + * @param args An optional array of arguments that are passed to the doneCallbacks. + * @see {@link https://api.jquery.com/deferred.resolveWith/} + * @since 1.5 + */ + resolveWith(context: object, args?: ArrayLike): this; + } + + namespace Deferred { + interface Callback3 { + (t: T, u: U, v: V): void; + } + + interface Callback { + (...args: T[]): void; + } /** - * 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 + * @deprecated */ - pipe - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN3): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR1, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter?: null): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR, - progressFilter?: null): JQuery.Promise; - /** - * 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 - (doneFilter: ((...t: TR[]) => JQuery.Promise | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): JQuery.Promise; + interface DoneCallback extends Callback { } /** - * 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 + * @deprecated */ - then - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN3): JQuery.Promise; + interface FailCallback extends Callback { } + /** - * 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 + * @deprecated */ - then - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR1, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; + interface AlwaysCallback extends Callback { } + /** - * 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 + * @deprecated */ - then - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN1): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: null, - progressFilter: (...t: TN[]) => JQuery.Promise | Thenable | AN): JQuery.Promise; - /** - * 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 - (doneFilter: (...t: TR[]) => JQuery.Promise | Thenable | AR1, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR2, - progressFilter?: null): JQuery.Promise; - /** - * 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 - (doneFilter: null, - failFilter: (...t: TJ[]) => JQuery.Promise | Thenable | AR, - progressFilter?: null): JQuery.Promise; - /** - * 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 - (doneFilter: ((...t: TR[]) => JQuery.Promise | Thenable | AR) | null, - failFilter?: null, - progressFilter?: null): JQuery.Promise; + interface ProgressCallback extends Callback { } } // endregion diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 7347a8a415..e6a9907958 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -4579,9 +4579,9 @@ function JQueryStatic() { } function Promise2() { - const t = $.Deferred() as JQuery.Promise2; - const u = $.Deferred() as JQuery.Promise2; - const v = $.Deferred() as JQuery.Promise2; + const t: JQuery.Promise2 = {} as any; + const u: JQuery.Promise2 = {} as any; + const v: JQuery.Promise2 = {} as any; // 3 parameters { @@ -4746,12 +4746,9 @@ function JQueryStatic() { $.when(task1, task2, task3) .done((r1, r2, r3) => { - // $ExpectType One - r1; - // $ExpectType Two - r2; - // $ExpectType Three - r3; + r1; // $ExpectType One + r2; // $ExpectType Two + r3; // $ExpectType Three }); } @@ -5916,39 +5913,33 @@ function _Promise(p: JQuery.Promise) { a; // $ExpectType string }, (a) => { a; // $ExpectType Error - }); + }, null); p.then((a) => { a; // $ExpectType string }, (a) => { a; // $ExpectType Error - }, null); - - p.then(null, (a) => { - a; // $ExpectType Error }); p.then(null, (a) => { a; // $ExpectType Error }, null); - p.then((a) => { - a; // $ExpectType string + p.then(null, (a) => { + a; // $ExpectType Error }); - p.then((a) => { - a; // $ExpectType string - }, null); - p.then((a) => { a; // $ExpectType string }, null, null); - p.then(null); + p.then((a) => { + a; // $ExpectType string + }, null); - p.then(null, null); - - p.then(null, null, null); + p.then((a) => { + a; // $ExpectType string + }); function doneFilter() { p.then(() => {