diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index ac047d0167..b71bfbbed3 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -38,7 +38,7 @@ declare const $: JQueryStatic; // Used by JQuery.Event type _Event = Event; -interface JQuery { +interface JQuery extends Iterable { /** * A string containing the jQuery version number. * @@ -1368,7 +1368,7 @@ interface JQuery { * @see {@link https://api.jquery.com/offset/} * @since 1.2 */ - offset(): JQuery.Coordinates; + offset(): JQuery.Coordinates | undefined; /** * Get the closest ancestor element that is positioned. * @@ -1793,6 +1793,7 @@ interface JQuery { * @param handler A function to execute after the DOM is ready. * @see {@link https://api.jquery.com/ready/} * @since 1.0 + * @deprecated 3.0 */ ready(handler: ($: JQueryStatic) => void): this; /** @@ -2329,7 +2330,7 @@ interface JQuery { * @see {@link https://api.jquery.com/val/} * @since 1.0 */ - val(): string | number | string[] | null | undefined; + val(): string | number | string[] | undefined; /** * Set the CSS width of each element in the set of matched elements. * @@ -2389,12 +2390,22 @@ interface JQuery { * @since 1.4 */ wrapInner(wrappingElement: JQuery.Selector | JQuery.htmlString | Element | JQuery | ((this: TElement, index: number) => string | JQuery | Element)): this; + + [n: number]: TElement; } -interface JQuery extends ArrayLike, Iterable { } - interface JQueryStatic { - Event: JQuery.Event; + /** + * A factory function that returns a chainable utility object with methods to register multiple + * callbacks into callback queues, invoke callback queues, and relay the success or failure state of + * any synchronous or asynchronous function. + * + * @param beforeStart A function that is called just before the constructor returns. + * @see {@link https://api.jquery.com/jQuery.Deferred/} + * @since 1.5 + */ + Deferred: JQuery.DeferredStatic; + Event: JQuery.EventStatic; /** * Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize * CSS property naming, or create custom properties. @@ -2499,20 +2510,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.Callbacks/} * @since 1.7 */ - Callbacks(flags?: string): JQuery.Callbacks; - /** - * A factory function that returns a chainable utility object with methods to register multiple - * callbacks into callback queues, invoke callback queues, and relay the success or failure state of - * any synchronous or asynchronous function. - * - * @param beforeStart A function that is called just before the constructor returns. - * @see {@link https://api.jquery.com/jQuery.Deferred/} - * @since 1.5 - */ - Deferred(beforeStart?: (this: JQuery.Deferred, - deferred: JQuery.Deferred) => void): JQuery.Deferred; + Callbacks(flags?: string): JQuery.Callbacks; /** * Perform an asynchronous HTTP (Ajax) request. * @@ -2908,6 +2906,7 @@ interface JQueryStatic { * @param hold Indicates whether the ready hold is being requested or released * @see {@link https://api.jquery.com/jQuery.holdReady/} * @since 1.6 + * @deprecated 3.2 */ holdReady(hold: boolean): void; /** @@ -2934,6 +2933,7 @@ interface JQueryStatic { * @param obj Object to test whether or not it is an array. * @see {@link https://api.jquery.com/jQuery.isArray/} * @since 1.3 + * @deprecated 3.2 */ isArray(obj: any): obj is any[]; /** @@ -2943,7 +2943,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.isEmptyObject/} * @since 1.4 */ - isEmptyObject(obj: any): boolean; + isEmptyObject(obj: any): obj is {}; /** * Determine if the argument passed is a JavaScript function object. * @@ -3265,9 +3265,52 @@ interface JQueryStatic { * @since 1.12-2.2 */ uniqueSort(array: T[]): T[]; - when(jqxhr1: JQuery.jqXHR, jqxhr2: JQuery.jqXHR, jqxhr3: JQuery.jqXHR): JQuery.Promise<[T | U | V, string, JQuery.jqXHR]>; - when(jqxhr1: JQuery.jqXHR, jqxhr2: JQuery.jqXHR): JQuery.Promise<[T | U, string, JQuery.jqXHR]>; - when(jqxhr1: JQuery.jqXHR): JQuery.Promise>; + /** + * 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. + * + * @see {@link https://api.jquery.com/jQuery.when/} + * @since 1.5 + */ + 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. + * + * @see {@link https://api.jquery.com/jQuery.when/} + * @since 1.5 + */ + when + (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. @@ -3276,7 +3319,16 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.when/} * @since 1.5 */ - when(...deferreds: any[]): JQuery.Promise; + when(...deferreds: Array | 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. + * + * @param deferreds Zero or more Thenable objects. + * @see {@link https://api.jquery.com/jQuery.when/} + * @since 1.5 + */ + when(...deferreds: any[]): JQuery.Promise; } declare namespace JQuery { @@ -3482,7 +3534,7 @@ declare namespace JQuery { * XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from * within the beforeSend function. */ - headers?: PlainObject; + headers?: PlainObject; /** * Allow the request to be successful only if the response has changed since the last request. This is * done by checking the Last-Modified header. Default value is false, ignoring the header. In jQuery @@ -3578,6 +3630,7 @@ declare namespace JQuery { * A username to be used with XMLHttpRequest in response to an HTTP access authentication request. */ username?: string; + // ActiveXObject requires "lib": ["scripthost"] which consumers would also require /** * Callback for creating the XMLHttpRequest object. Defaults to the ActiveXObject when available (IE), * the XMLHttpRequest otherwise. Override to provide your own implementation for XMLHttpRequest or @@ -3591,12 +3644,14 @@ declare namespace JQuery { * requests requiring it would ignore this flag. For this reason, we recommend using jQuery 1.5.1+ * should you require the use of it. */ - xhrFields?: PlainObject; + xhrFields?: XHRFields; } - // Status codes not listed require type annotations when defining the callback type StatusCodeCallbacks = { + // region Success Status Codes + // jQuery treats 2xx and 304 status codes as a success + 200?: SuccessCallback; 201?: SuccessCallback; 202?: SuccessCallback; @@ -3699,7 +3754,10 @@ declare namespace JQuery { 299?: SuccessCallback; 304?: SuccessCallback; - // Standard 3xx, 4xx, and 5xx status codes that are considered an error + // endregion + + // region Error Status Codes + 300?: ErrorCallback; 301?: ErrorCallback; 302?: ErrorCallback; @@ -3708,6 +3766,97 @@ declare namespace JQuery { 306?: ErrorCallback; 307?: ErrorCallback; 308?: ErrorCallback; + 309?: ErrorCallback; + 310?: ErrorCallback; + 311?: ErrorCallback; + 312?: ErrorCallback; + 313?: ErrorCallback; + 314?: ErrorCallback; + 315?: ErrorCallback; + 316?: ErrorCallback; + 317?: ErrorCallback; + 318?: ErrorCallback; + 319?: ErrorCallback; + 320?: ErrorCallback; + 321?: ErrorCallback; + 322?: ErrorCallback; + 323?: ErrorCallback; + 324?: ErrorCallback; + 325?: ErrorCallback; + 326?: ErrorCallback; + 327?: ErrorCallback; + 328?: ErrorCallback; + 329?: ErrorCallback; + 330?: ErrorCallback; + 331?: ErrorCallback; + 332?: ErrorCallback; + 333?: ErrorCallback; + 334?: ErrorCallback; + 335?: ErrorCallback; + 336?: ErrorCallback; + 337?: ErrorCallback; + 338?: ErrorCallback; + 339?: ErrorCallback; + 340?: ErrorCallback; + 341?: ErrorCallback; + 342?: ErrorCallback; + 343?: ErrorCallback; + 344?: ErrorCallback; + 345?: ErrorCallback; + 346?: ErrorCallback; + 347?: ErrorCallback; + 348?: ErrorCallback; + 349?: ErrorCallback; + 350?: ErrorCallback; + 351?: ErrorCallback; + 352?: ErrorCallback; + 353?: ErrorCallback; + 354?: ErrorCallback; + 355?: ErrorCallback; + 356?: ErrorCallback; + 357?: ErrorCallback; + 358?: ErrorCallback; + 359?: ErrorCallback; + 360?: ErrorCallback; + 361?: ErrorCallback; + 362?: ErrorCallback; + 363?: ErrorCallback; + 364?: ErrorCallback; + 365?: ErrorCallback; + 366?: ErrorCallback; + 367?: ErrorCallback; + 368?: ErrorCallback; + 369?: ErrorCallback; + 370?: ErrorCallback; + 371?: ErrorCallback; + 372?: ErrorCallback; + 373?: ErrorCallback; + 374?: ErrorCallback; + 375?: ErrorCallback; + 376?: ErrorCallback; + 377?: ErrorCallback; + 378?: ErrorCallback; + 379?: ErrorCallback; + 380?: ErrorCallback; + 381?: ErrorCallback; + 382?: ErrorCallback; + 383?: ErrorCallback; + 384?: ErrorCallback; + 385?: ErrorCallback; + 386?: ErrorCallback; + 387?: ErrorCallback; + 388?: ErrorCallback; + 389?: ErrorCallback; + 390?: ErrorCallback; + 391?: ErrorCallback; + 392?: ErrorCallback; + 393?: ErrorCallback; + 394?: ErrorCallback; + 395?: ErrorCallback; + 396?: ErrorCallback; + 397?: ErrorCallback; + 398?: ErrorCallback; + 399?: ErrorCallback; 400?: ErrorCallback; 401?: ErrorCallback; 402?: ErrorCallback; @@ -3727,15 +3876,87 @@ declare namespace JQuery { 416?: ErrorCallback; 417?: ErrorCallback; 418?: ErrorCallback; + 419?: ErrorCallback; + 420?: ErrorCallback; 421?: ErrorCallback; 422?: ErrorCallback; 423?: ErrorCallback; 424?: ErrorCallback; + 425?: ErrorCallback; 426?: ErrorCallback; + 427?: ErrorCallback; 428?: ErrorCallback; 429?: ErrorCallback; + 430?: ErrorCallback; 431?: ErrorCallback; + 432?: ErrorCallback; + 433?: ErrorCallback; + 434?: ErrorCallback; + 435?: ErrorCallback; + 436?: ErrorCallback; + 437?: ErrorCallback; + 438?: ErrorCallback; + 439?: ErrorCallback; + 440?: ErrorCallback; + 441?: ErrorCallback; + 442?: ErrorCallback; + 443?: ErrorCallback; + 444?: ErrorCallback; + 445?: ErrorCallback; + 446?: ErrorCallback; + 447?: ErrorCallback; + 448?: ErrorCallback; + 449?: ErrorCallback; + 450?: ErrorCallback; 451?: ErrorCallback; + 452?: ErrorCallback; + 453?: ErrorCallback; + 454?: ErrorCallback; + 455?: ErrorCallback; + 456?: ErrorCallback; + 457?: ErrorCallback; + 458?: ErrorCallback; + 459?: ErrorCallback; + 460?: ErrorCallback; + 461?: ErrorCallback; + 462?: ErrorCallback; + 463?: ErrorCallback; + 464?: ErrorCallback; + 465?: ErrorCallback; + 466?: ErrorCallback; + 467?: ErrorCallback; + 468?: ErrorCallback; + 469?: ErrorCallback; + 470?: ErrorCallback; + 471?: ErrorCallback; + 472?: ErrorCallback; + 473?: ErrorCallback; + 474?: ErrorCallback; + 475?: ErrorCallback; + 476?: ErrorCallback; + 477?: ErrorCallback; + 478?: ErrorCallback; + 479?: ErrorCallback; + 480?: ErrorCallback; + 481?: ErrorCallback; + 482?: ErrorCallback; + 483?: ErrorCallback; + 484?: ErrorCallback; + 485?: ErrorCallback; + 486?: ErrorCallback; + 487?: ErrorCallback; + 488?: ErrorCallback; + 489?: ErrorCallback; + 490?: ErrorCallback; + 491?: ErrorCallback; + 492?: ErrorCallback; + 493?: ErrorCallback; + 494?: ErrorCallback; + 495?: ErrorCallback; + 496?: ErrorCallback; + 497?: ErrorCallback; + 498?: ErrorCallback; + 499?: ErrorCallback; 500?: ErrorCallback; 501?: ErrorCallback; 502?: ErrorCallback; @@ -3745,9 +3966,106 @@ declare namespace JQuery { 506?: ErrorCallback; 507?: ErrorCallback; 508?: ErrorCallback; + 509?: ErrorCallback; 510?: ErrorCallback; 511?: ErrorCallback; - } & { [index: number]: SuccessCallback | ErrorCallback; }; + 512?: ErrorCallback; + 513?: ErrorCallback; + 514?: ErrorCallback; + 515?: ErrorCallback; + 516?: ErrorCallback; + 517?: ErrorCallback; + 518?: ErrorCallback; + 519?: ErrorCallback; + 520?: ErrorCallback; + 521?: ErrorCallback; + 522?: ErrorCallback; + 523?: ErrorCallback; + 524?: ErrorCallback; + 525?: ErrorCallback; + 526?: ErrorCallback; + 527?: ErrorCallback; + 528?: ErrorCallback; + 529?: ErrorCallback; + 530?: ErrorCallback; + 531?: ErrorCallback; + 532?: ErrorCallback; + 533?: ErrorCallback; + 534?: ErrorCallback; + 535?: ErrorCallback; + 536?: ErrorCallback; + 537?: ErrorCallback; + 538?: ErrorCallback; + 539?: ErrorCallback; + 540?: ErrorCallback; + 541?: ErrorCallback; + 542?: ErrorCallback; + 543?: ErrorCallback; + 544?: ErrorCallback; + 545?: ErrorCallback; + 546?: ErrorCallback; + 547?: ErrorCallback; + 548?: ErrorCallback; + 549?: ErrorCallback; + 550?: ErrorCallback; + 551?: ErrorCallback; + 552?: ErrorCallback; + 553?: ErrorCallback; + 554?: ErrorCallback; + 555?: ErrorCallback; + 556?: ErrorCallback; + 557?: ErrorCallback; + 558?: ErrorCallback; + 559?: ErrorCallback; + 560?: ErrorCallback; + 561?: ErrorCallback; + 562?: ErrorCallback; + 563?: ErrorCallback; + 564?: ErrorCallback; + 565?: ErrorCallback; + 566?: ErrorCallback; + 567?: ErrorCallback; + 568?: ErrorCallback; + 569?: ErrorCallback; + 570?: ErrorCallback; + 571?: ErrorCallback; + 572?: ErrorCallback; + 573?: ErrorCallback; + 574?: ErrorCallback; + 575?: ErrorCallback; + 576?: ErrorCallback; + 577?: ErrorCallback; + 578?: ErrorCallback; + 579?: ErrorCallback; + 580?: ErrorCallback; + 581?: ErrorCallback; + 582?: ErrorCallback; + 583?: ErrorCallback; + 584?: ErrorCallback; + 585?: ErrorCallback; + 586?: ErrorCallback; + 587?: ErrorCallback; + 588?: ErrorCallback; + 589?: ErrorCallback; + 590?: ErrorCallback; + 591?: ErrorCallback; + 592?: ErrorCallback; + 593?: ErrorCallback; + 594?: ErrorCallback; + 595?: ErrorCallback; + 596?: ErrorCallback; + 597?: ErrorCallback; + 598?: ErrorCallback; + 599?: ErrorCallback; + + // endregion + } & { + // Status codes not listed require type annotations when defining the callback + [index: number]: SuccessCallback | ErrorCallback; + }; + + // Writable properties on XMLHttpRequest + interface XHRFields extends Partial> { } } interface Transport { @@ -3764,95 +4082,14 @@ declare namespace JQuery { /** * @see {@link http://api.jquery.com/jquery.ajax/#jqXHR} */ - interface jqXHR extends Pick { - responseJSON: any; - statusCode(map: Ajax.StatusCodeCallbacks): void; + interface jqXHR extends Promise3, never, + Ajax.SuccessTextStatus, Ajax.ErrorTextStatus, never, + jqXHR, string, never>, + Pick, + Partial> { + responseJSON?: 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>, - ...alwaysCallbacks: Array>>): this; - /** - * 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: (jqXHR: this, textStatus: Ajax.ErrorTextStatus, errorThrown: string) => never): Deferred; - /** - * 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: (jqXHR: this, textStatus: Ajax.ErrorTextStatus, errorThrown: string) => UResolve | Thenable): Deferred; - /** - * 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; - /** - * 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: ((data: TResolve, textStatus: Ajax.SuccessTextStatus, jqXHR: this) => UResolve | Thenable) | null, - failFilter?: ((jqXHR: this, textStatus: Ajax.ErrorTextStatus, errorThrown: string) => UReject | Thenable) | null): Deferred; - /** - * 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. * @@ -3860,50 +4097,40 @@ declare namespace JQuery { * @since 1.7 */ state(): 'pending' | 'resolved' | 'rejected'; - /** - * 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: ((data: TResolve, textStatus: Ajax.SuccessTextStatus, jqXHR: this) => UResolve | Thenable) | null, - failFilter?: ((jqXHR: this, textStatus: Ajax.ErrorTextStatus, errorThrown: string) => UReject | Thenable) | null): Deferred; + statusCode(map: Ajax.StatusCodeCallbacks): void; } namespace jqXHR { - interface DoneCallback { - (data: TResolve, textStatus: Ajax.SuccessTextStatus, jqXHR: jqXHR): void; - } + /** + * @deprecated + */ + interface DoneCallback> extends Deferred.Callback3 { } - interface FailCallback { - (jqXHR: TResolve, textStatus: Ajax.ErrorTextStatus, errorThrown: string): void; - } + /** + * @deprecated + */ + interface FailCallback extends Deferred.Callback3 { } - interface AlwaysCallback { - (data_jqXHR: TResolve | jqXHR, textStatus: Ajax.TextStatus, jqXHR_errorThrown: jqXHR | string): void; - } - - interface ProgressCallback { - (...values: any[]): void; - } + /** + * @deprecated + */ + interface AlwaysCallback> extends Deferred.Callback3 { } } // endregion // region Callbacks - interface Callbacks { + interface Callbacks { /** * Add a callback or a collection of callbacks to a callback list. * + * @param callback A function, or array of functions, that are to be added to the callback list. * @param callbacks A function, or array of functions, that are to be added to the callback list. * @see {@link https://api.jquery.com/callbacks.add/} * @since 1.7 */ - add(callbacks: TypeOrArray): this; + add(callback: TypeOrArray, ...callbacks: Array>): this; /** * Disable a callback list from doing anything more. * @@ -3941,7 +4168,7 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/callbacks.fireWith/} * @since 1.7 */ - fireWith(context?: object, args?: TypeOrArray): this; + fireWith(context: object, args?: ArrayLike): this; /** * Determine if the callbacks have already been called at least once. * @@ -3957,7 +4184,7 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/callbacks.has/} * @since 1.7 */ - has(callback?: Function): boolean; + has(callback?: T): boolean; /** * Lock a callback list in its current state. * @@ -3979,7 +4206,7 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/callbacks.remove/} * @since 1.7 */ - remove(callbacks: TypeOrArray): this; + remove(...callbacks: T[]): this; } // endregion @@ -4000,7 +4227,28 @@ declare namespace JQuery { */ interface Thenable extends PromiseLike { } - interface Deferred { + // Type parameter guide + // -------------------- + // Each type parameter represents a parameter in one of the three possible callbacks. + // + // The first letter indicates which position the parameter is in. + // + // T = A = 1st position + // U = B = 2nd position + // V = C = 3rd position + // + // The second letter indicates which whether it is a [R]esolve, Re[J]ect, or [N]otify value. + // + // The third letter indicates whether the value is returned in the [D]one filter, [F]ail filter, or [P]rogress filter. + /** + * This object provides a subset of the methods of the Deferred object (then, done, fail, always, + * pipe, progress, state and promise) to prevent users from changing the state of the Deferred. + * + * @see {@link http://api.jquery.com/Types/#Promise} + */ + interface Promise3 { /** * Add handlers to be called when the Deferred object is either resolved or rejected. * @@ -4009,16 +4257,8 @@ declare namespace JQuery { * @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 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: TReject[]) => UResolve | Thenable): Deferred; + always(alwaysCallback: TypeOrArray>, + ...alwaysCallbacks: Array>>): this; /** * Add handlers to be called when the Deferred object is resolved. * @@ -4027,8 +4267,8 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.done/} * @since 1.5 */ - done(doneCallback: TypeOrArray>, - ...doneCallbacks: Array>>): this; + done(doneCallback: TypeOrArray>, + ...doneCallbacks: Array>>): this; /** * Add handlers to be called when the Deferred object is rejected. * @@ -4037,41 +4277,8 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.fail/} * @since 1.5 */ - fail(failCallback: TypeOrArray>, - ...failCallbacks: Array>>): this; - /** - * 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: TNotify[]): 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: TNotify[]): this; - /** - * 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: ((...values: TResolve[]) => UResolve | Thenable) | null, - failFilter?: ((...reasons: TReject[]) => UReject | Thenable) | null, - progressFilter?: ((...values: TNotify[]) => TNotify | Thenable) | null): Deferred; + fail(failCallback: TypeOrArray>, + ...failCallbacks: Array>>): this; /** * Add handlers to be called when the Deferred object generates progress notifications. * @@ -4081,8 +4288,8 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.progress/} * @since 1.7 */ - progress(progressCallback: TypeOrArray>, - ...progressCallbacks: Array>>): this; + progress(progressCallback: TypeOrArray>, + ...progressCallbacks: Array>>): this; /** * Return a Deferred's Promise object. * @@ -4090,48 +4297,14 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.promise/} * @since 1.5 */ - promise(target: TTarget): JQuery.Promise & TTarget; + promise(target: TTarget): this & TTarget; /** * Return a Deferred's Promise object. * * @see {@link https://api.jquery.com/deferred.promise/} * @since 1.5 */ - promise(): JQuery.Promise; - /** - * 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: TReject[]): 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: TReject[]): 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: TResolve[]): 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: TResolve[]): this; + promise(): this; /** * Determine the current state of a Deferred object. * @@ -4139,56 +4312,7 @@ declare namespace JQuery { * @since 1.7 */ state(): 'pending' | 'resolved' | 'rejected'; - /** - * 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: ((...values: TResolve[]) => UResolve | Thenable) | null, - failFilter?: ((...reasons: TReject[]) => UReject | Thenable) | null, - progressFilter?: ((...values: TNotify[]) => TNotify | Thenable) | null): Deferred; - } - namespace Deferred { - interface DoneCallback { - (...values: TResolve[]): void; - } - - interface FailCallback { - (...reasons: TReject[]): void; - } - - interface AlwaysCallback { - (...values_reasons: Array): void; - } - - interface ProgressCallback { - (...values: TNotify[]): void; - } - } - - /** - * This object provides a subset of the methods of the Deferred object (then, done, fail, always, - * pipe, progress, state and promise) to prevent users from changing the state of the Deferred. - * - * @see {@link http://api.jquery.com/Types/#Promise} - */ - interface Promise extends Pick, - 'always' | 'done' | 'fail' | 'progress' | 'promise' | 'state'> { - /** - * 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: TReject[]) => UReject | Thenable): Promise; /** * Utility method to filter and/or chain Deferreds. * @@ -4200,11 +4324,169 @@ declare namespace JQuery { * @since 1.7 * @deprecated 1.8 */ - pipe(doneFilter: ((...values: TResolve[]) => UResolve | Thenable) | null, - failFilter?: ((...reasons: TReject[]) => UReject | Thenable) | null, - progressFilter?: ((...values: TNotify[]) => TNotify | Thenable) | null): Promise; + pipe + (doneFilter: (t: TR, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: null, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, u: UJ, v: VJ) => Promise3 | Thenable | AJF, + progressFilter?: null): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise3; + /** * Add handlers to be called when the Deferred object is resolved, rejected, or still in progress. * @@ -4214,11 +4496,551 @@ declare namespace JQuery { * @see {@link https://api.jquery.com/deferred.then/} * @since 1.8 */ - then(doneFilter: ((...values: TResolve[]) => UResolve | Thenable) | null, - failFilter?: ((...reasons: TReject[]) => UReject | Thenable) | null, - progressFilter?: ((...values: TNotify[]) => TNotify | Thenable) | null): Promise; + then + (doneFilter: (t: TR, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: null, + progressFilter: (t: TN, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UN, v: VN) => Promise3 | Thenable | ANP): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter?: null): Promise3; + /** + * 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, u: UJ, v: VJ) => Promise3 | Thenable | ARF, + progressFilter?: null): Promise3; + /** + * 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, u: UR, v: VR) => Promise3 | Thenable | ARD, + failFilter?: null, + progressFilter?: null): Promise3; + + /** + * 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: (t: TJ, u: UJ, v: VJ) => Promise3 | Thenable | ARF): Promise3; + } + + /** + * This object provides a subset of the methods of the Deferred object (then, done, fail, always, + * pipe, progress, state and promise) to prevent users from changing the state of the Deferred. + * + * @see {@link http://api.jquery.com/Types/#Promise} + */ + interface Promise2 extends Promise3 { } + + /** + * This object provides a subset of the methods of the Deferred object (then, done, fail, always, + * pipe, progress, state and promise) to prevent users from changing the state of the Deferred. + * + * @see {@link http://api.jquery.com/Types/#Promise} + */ + interface Promise { + /** + * 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'; + + /** + * 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: TJ[]) => 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: TJ[]) => 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: TJ[]) => 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: TJ[]) => 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. + * + * @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: (...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; + } + + /** + * @deprecated + */ + interface DoneCallback extends Callback { } + + /** + * @deprecated + */ + interface FailCallback extends Callback { } + + /** + * @deprecated + */ + interface AlwaysCallback extends Callback { } + + /** + * @deprecated + */ + interface ProgressCallback extends Callback { } } // endregion @@ -4305,10 +5127,11 @@ declare namespace JQuery { complete?(this: TElement): void; } + // This should be a class but doesn't work correctly under the JQuery namespace. Tween should be an inner class of jQuery. // Undocumented // https://github.com/jquery/api.jquery.com/issues/391 // https://github.com/jquery/api.jquery.com/issues/61 - class Tween { + interface Tween { easing: string; elem: TElement; end: number; @@ -4328,29 +5151,12 @@ declare namespace JQuery { // region Events + // region Event + // This should be a class but doesn't work correctly under the JQuery namespace. Event should be an inner class of jQuery. - interface Event { - /** - * The current DOM element within the event bubbling phase. - * - * @see {@link https://api.jquery.com/event.currentTarget/} - * @since 1.3 - */ - currentTarget: TTarget; - /** - * An optional object of data passed to an event method when the current executing handler is bound. - * - * @see {@link https://api.jquery.com/event.data/} - * @since 1.1 - */ - data: TData; - /** - * The element where the currently-called jQuery event handler was attached. - * - * @see {@link https://api.jquery.com/event.delegateTarget/} - * @since 1.7 - */ - delegateTarget: TTarget; + + // Instance members + interface Event { /** * Indicates whether the META key was pressed when the event fired. * @@ -4379,13 +5185,6 @@ declare namespace JQuery { * @since 1.0.4 */ pageY: number; - /** - * The other DOM element involved in the event, if any. - * - * @see {@link https://api.jquery.com/event.relatedTarget/} - * @since 1.1.4 - */ - relatedTarget: TTarget | null; /** * The last value returned by an event handler that was triggered by this event, unless the value was undefined. * @@ -4393,13 +5192,6 @@ declare namespace JQuery { * @since 1.3 */ result: any; - /** - * The DOM element that initiated the event. - * - * @see {@link https://api.jquery.com/event.target/} - * @since 1.0 - */ - target: TTarget; /** * The difference in milliseconds between the time the browser created the event and January 1, 1970. * @@ -4471,18 +5263,64 @@ declare namespace JQuery { stopPropagation(): void; } - interface Event extends Partial extends Partial> { - originalTarget?: TTarget; + /** + * The current DOM element within the event bubbling phase. + * + * @see {@link https://api.jquery.com/event.currentTarget/} + * @since 1.3 + */ + currentTarget: TTarget; + /** + * An optional object of data passed to an event method when the current executing handler is bound. + * + * @see {@link https://api.jquery.com/event.data/} + * @since 1.1 + */ + data: TData; + /** + * The element where the currently-called jQuery event handler was attached. + * + * @see {@link https://api.jquery.com/event.delegateTarget/} + * @since 1.7 + */ + delegateTarget: TTarget; originalEvent: _Event; - new(event: string, properties?: T): JQuery.Event & T; - new(properties: T): JQuery.Event & T; - (event: string, properties?: T): JQuery.Event & T; - (properties: T): JQuery.Event & T; + /** + * The other DOM element involved in the event, if any. + * + * @see {@link https://api.jquery.com/event.relatedTarget/} + * @since 1.1.4 + */ + relatedTarget: TTarget | null; + /** + * The DOM element that initiated the event. + * + * @see {@link https://api.jquery.com/event.target/} + * @since 1.0 + */ + target: TTarget; } + // Static members + interface EventStatic { + (event: string, properties?: T): JQuery.Event & T; + (properties: T): JQuery.Event & T; + new (event: string, properties?: T): JQuery.Event & T; + new (properties: T): JQuery.Event & T; + } + + interface EventLike { + type: string; + } + + // endregion + // Extra parameters can be passed from trigger() interface EventHandler { (this: TContext, eventObject: JQuery.Event, ...args: any[]): void | false | any; @@ -4633,7 +5471,7 @@ declare namespace JQuery { // region Legacy types -interface JQueryCallback extends JQuery.Callbacks { } +interface JQueryCallback extends JQuery.Callbacks { } interface JQueryDeferred extends JQuery.Deferred { } interface JQueryEventConstructor extends JQuery.Event { } interface JQueryDeferred extends JQuery.Deferred { } diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 438f36c79b..35b91fe1d3 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1,3 +1,5 @@ +// tslint:disable:interface-name + function JQuery() { function type_assertion() { const $el = $(document.createElement('canvas')); @@ -11,7 +13,10 @@ function JQuery() { } function arrayLike() { - $('div')[0] === new HTMLElement(); + // $ExpectType HTMLElement + $('div')[0]; + + $('div')[0] = new HTMLElement(); } function ajax() { @@ -601,7 +606,7 @@ function JQuery() { }; }); - // $ExpectType Coordinates + // $ExpectType Coordinates | undefined $('p').offset(); } @@ -1186,9 +1191,6 @@ function JQuery() { this; }); - // $ExpectType JQuery - $('p').toggle('linear'); - // $ExpectType JQuery $('p').toggle(true); @@ -3025,7 +3027,7 @@ function JQuery() { return 'myVal'; }); - // $ExpectType string | number | string[] | null | undefined + // $ExpectType string | number | string[] | undefined $('p').val(); } } @@ -3479,10 +3481,10 @@ function JQueryStatic() { } function call_signature() { - // #ExpectType JQuery + // $ExpectType JQuery $('

', new Document()); - // #ExpectType JQuery + // $ExpectType JQuery $('

', { class: 'my-div', on: { @@ -3492,57 +3494,154 @@ function JQueryStatic() { } }); - // #ExpectType JQuery + // $ExpectType JQuery $('span', new HTMLElement()); - // #ExpectType JQuery + // $ExpectType JQuery $('span', new Document()); - // #ExpectType JQuery + // $ExpectType JQuery $('span', $('p')); - // #ExpectType JQuery + // $ExpectType JQuery $('span'); - // #ExpectType JQuery + // $ExpectType JQuery $('

'); - // #ExpectType JQuery + // $ExpectType JQuery $(new HTMLElement()); - // #ExpectType JQuery + // $ExpectType JQuery $([new HTMLElement()]); - // #ExpectType JQuery + // $ExpectType JQuery $({ foo: 'bar', hello: 'world' }); - // #ExpectType JQuery + // $ExpectType JQuery $($('p')); - // #ExpectType JQuery + // $ExpectType JQuery $(function($) { - // #ExpectType Document + // $ExpectType Document this; - // #ExpectType JQueryStatic + // $ExpectType JQueryStatic $; }); - // #ExpectType JQuery + // $ExpectType JQuery $(); } + function Event() { + // $ExpectType EventStatic + $.Event; + } + + function cssHooks() { + // $ExpectType PlainObject> + $.cssHooks; + } + + function cssNumber() { + // $ExpectType PlainObject + $.cssNumber; + } + + function fn() { + // $ExpectType JQuery + $.fn; + } + + function fx() { + function interval() { + // $ExpectType number + $.fx.interval; + } + + function off() { + // $ExpectType boolean + $.fx.off; + } + + function step() { + // $ExpectType PlainObject> + $.fx.step; + } + } + + function ready() { + // $ExpectType Thenable> + $.ready; + } + + function support() { + // $ExpectType PlainObject + $.support; + } + + function valHooks() { + // $ExpectType PlainObject> + $.valHooks; + } + function Callbacks() { - // #ExpectType Callbacks + // $ExpectType Callbacks $.Callbacks('once'); - // #ExpectType Callbacks + // $ExpectType Callbacks $.Callbacks(); } - function Event() { - function constructor() { - const e = $.Event('click'); - e.stopPropagation(); + function Deferred() { + function call_signature() { + // $ExpectType Deferred + $.Deferred(function(deferred) { + // $ExpectType Deferred + this; + // $ExpectType Deferred + deferred; + }); + + // $ExpectType Deferred + $.Deferred(); + + // $ExpectType Deferred + $.Deferred(function(deferred) { + // $ExpectType Deferred + this; + // $ExpectType Deferred + deferred; + }); + + // $ExpectType Deferred + $.Deferred(); + + // $ExpectType Deferred + $.Deferred(function(deferred) { + // $ExpectType Deferred + this; + // $ExpectType Deferred + deferred; + }); + + // $ExpectType Deferred + $.Deferred(); + + // $ExpectType Deferred + $.Deferred(function(deferred) { + // $ExpectType Deferred + this; + // $ExpectType Deferred + deferred; + }); + + // $ExpectType Deferred + $.Deferred(); + } + + function exceptionHook() { + $.Deferred.exceptionHook = undefined; } } @@ -3999,8 +4098,12 @@ function JQueryStatic() { } function isEmptyObject() { - // $ExpectType boolean - $.isEmptyObject({}); + function type_guard(obj: object) { + if ($.isEmptyObject(obj)) { + // $ExpectType {} + obj; + } + } } function isFunction() { @@ -4342,24 +4445,346 @@ function JQueryStatic() { } function when() { - const t = $.ajax() as JQuery.jqXHR; - const u = $.ajax() as JQuery.jqXHR; - const v = $.ajax() as JQuery.jqXHR; + interface I1 { kind: 'I1'; } + interface I2 { kind: 'I2'; } + interface I3 { kind: 'I3'; } + interface I4 { kind: 'I4'; } + interface I5 { kind: 'I5'; } + interface I6 { kind: 'I6'; } + interface I7 { kind: 'I7'; } + interface I8 { kind: 'I8'; } + interface I9 { kind: 'I9'; } - // $ExpectType Promise<[string | number | boolean, string, jqXHR], any, any> - $.when(t, u, v); + function Promise3() { + const t = $.ajax() as JQuery.jqXHR; + const u = $.ajax() as JQuery.jqXHR; + const v = $.ajax() as JQuery.jqXHR; - // $ExpectType Promise<[string | number, string, jqXHR], any, any> - $.when(t, u); + // // 3 parameters + // { + // const w = $.when(t, u, v); + // + // w.then((a, b, c) => { + // a[0]; // $ExpectType string + // a[1]; // $ExpectType SuccessTextStatus + // a[2]; // $ExpectType jqXHR + // b[0]; // $ExpectType number + // b[1]; // $ExpectType SuccessTextStatus + // b[2]; // $ExpectType jqXHR + // c[0]; // $ExpectType boolean + // c[1]; // $ExpectType SuccessTextStatus + // c[2]; // $ExpectType jqXHR + // }, (a, b, c) => { + // a[0]; // $ExpectType jqXHR + // a[1]; // $ExpectType ErrorTextStatus + // a[2]; // $ExpectType string + // b[0]; // $ExpectType jqXHR + // b[1]; // $ExpectType ErrorTextStatus + // b[2]; // $ExpectType string + // c[0]; // $ExpectType jqXHR + // c[1]; // $ExpectType ErrorTextStatus + // c[2]; // $ExpectType string + // }, (a, b, c) => { + // a; // $ExpectType never + // b; // $ExpectType never + // c; // $ExpectType never + // }); + // } + // + // // 2 parameters + // { + // const w = $.when(t, u); + // + // w.then((a, b) => { + // a[0]; // $ExpectType string + // a[1]; // $ExpectType SuccessTextStatus + // a[2]; // $ExpectType jqXHR + // b[0]; // $ExpectType number + // b[1]; // $ExpectType SuccessTextStatus + // b[2]; // $ExpectType jqXHR + // }, (a, b) => { + // a[0]; // $ExpectType jqXHR + // a[1]; // $ExpectType ErrorTextStatus + // a[2]; // $ExpectType string + // b[0]; // $ExpectType jqXHR + // b[1]; // $ExpectType ErrorTextStatus + // b[2]; // $ExpectType string + // }, (a, b) => { + // a; // $ExpectType never + // b; // $ExpectType never + // }); + // } - // $ExpectType Promise, any, any> - $.when(t); + // 1 parameter + { + const w = $.when(t); - // $ExpectType Promise - $.when($.Deferred()); + w.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType SuccessTextStatus + c; // $ExpectType jqXHR + }, (a, b, c) => { + a; // $ExpectType jqXHR + b; // $ExpectType ErrorTextStatus + c; // $ExpectType string + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + } - // $ExpectType Promise - $.when(); + function Promise2() { + const t: JQuery.Promise2 = {} as any; + const u: JQuery.Promise2 = {} as any; + const v: JQuery.Promise2 = {} as any; + + // // 3 parameters + // { + // const w = $.when(t, u, v); + // + // w.then((a, b, c) => { + // a[0]; // $ExpectType string + // a[1]; // $ExpectType boolean + // b[0]; // $ExpectType string + // b[1]; // $ExpectType boolean + // c[0]; // $ExpectType string + // c[1]; // $ExpectType boolean + // }, (a, b, c) => { + // a[0]; // $ExpectType Error + // a[1]; // $ExpectType any + // b[0]; // $ExpectType Error + // b[1]; // $ExpectType any + // c[0]; // $ExpectType Error + // c[1]; // $ExpectType any + // }, (a, b, c) => { + // a; // $ExpectType never + // b; // $ExpectType never + // c; // $ExpectType never + // }); + // } + // + // // 2 parameters + // { + // const w = $.when(t, u); + // + // w.then((a, b) => { + // a[0]; // $ExpectType string + // a[1]; // $ExpectType boolean + // b[0]; // $ExpectType string + // b[1]; // $ExpectType boolean + // }, (a, b) => { + // a[0]; // $ExpectType Error + // a[1]; // $ExpectType any + // b[0]; // $ExpectType Error + // b[1]; // $ExpectType any + // }, (a, b) => { + // a; // $ExpectType never + // b; // $ExpectType never + // }); + // } + + // 1 parameter + { + const w = $.when(t); + + w.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType boolean + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType any + }, (a, b) => { + a; // $ExpectType never + b; // $ExpectType never + }); + } + } + + function Promise() { + const p1: JQuery.Promise = {} as any; + const p2: JQuery.Promise = {} as any; + const p3: JQuery.Promise = {} as any; + + // 3 parameters + { + const w = $.when(p1, p2, p3); + + w.then((a, b, c) => { + a; // $ExpectType I1 + b; // $ExpectType I2 + c; // $ExpectType I3 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I3 + c; // $ExpectType I4 + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // 2 parameters + { + const w = $.when(p1, p2); + + w.then((a, b) => { + a; // $ExpectType I1 + b; // $ExpectType I2 + }, (a, b) => { + a; // $ExpectType I2 + b; // $ExpectType I3 + }, (a, b) => { + a; // $ExpectType never + b; // $ExpectType never + }); + } + + // 1 parameter + { + const w = $.when(p1); + + w.then(a => { + a; // $ExpectType I1 + }, a => { + a; // $ExpectType I2 + }, a => { + a; // $ExpectType never + }); + } + } + + function Thenable() { + const t1: JQuery.Thenable = {} as any; + const t2: JQuery.Thenable = {} as any; + const t3: JQuery.Thenable = {} as any; + + // 3 parameters + { + const w = $.when(t1, t2, t3); + + w.then((a, b, c) => { + a; // $ExpectType I1 + b; // $ExpectType I2 + c; // $ExpectType I3 + }, (a, b, c) => { + a; // $ExpectType any + b; // $ExpectType any + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // 2 parameters + { + const w = $.when(t1, t2); + + w.then((a, b) => { + a; // $ExpectType I1 + b; // $ExpectType I2 + }, (a, b) => { + a; // $ExpectType any + b; // $ExpectType any + }, (a, b) => { + a; // $ExpectType never + b; // $ExpectType never + }); + } + + // 1 parameter + { + const w = $.when(t1); + + w.then(a => { + a; // $ExpectType I1 + }, a => { + a; // $ExpectType any + }, a => { + a; // $ExpectType never + }); + } + } + + function value() { + const w = $.when('myVal1'); + + w.then(a => { + a; // $ExpectType string + }); + } + + function Zero() { + const w = $.when(); + + w.then(a => { + a; // $ExpectType never + }, a => { + a; // $ExpectType never + }, a => { + a; // $ExpectType never + }); + } + + // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/2725 + function issue_2725() { + function first() { + return $.when('1'); + } + + $.when().then(() => { + return first(); + }).then((value) => { + value; // $ExpectType string + }); + } + + // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/10159 + function issue_10159() { + interface One { result: number; } + interface Two { Result: number; } + interface Three { TheResult: number; } + + class AsyncRunner { + Run(): void { + const task1 = this.runTask1(); + const task2 = this.runTask2(); + const task3 = this.runTask3(); + + $.when(task1, task2, task3) + .then((r1, r2, r3) => { + r1; // $ExpectType One + r2; // $ExpectType Two + r3; // $ExpectType Three + }); + } + + runTask1() { + let dfd = $.Deferred(); + console.log('Task 1'); + setTimeout(() => { dfd.resolve({ result: 1 }); }, Math.floor(400 + Math.random() * 2000)); + return dfd.promise(); + } + + runTask2() { + let dfd = $.Deferred(); + console.log('Task 2'); + setTimeout(() => { dfd.resolve({ Result: 2 }); }, Math.floor(400 + Math.random() * 2000)); + return dfd.promise(); + } + + runTask3() { + let dfd = $.Deferred(); + console.log('Task 3'); + setTimeout(() => { dfd.resolve({ TheResult: 3 }); }, Math.floor(400 + Math.random() * 2000)); + return dfd.promise(); + } + } + } } } @@ -4529,6 +4954,86 @@ function AjaxSettings() { }); } +function Callbacks() { + function add() { + const callbacks = $.Callbacks(); + + // $ExpectType Callbacks + callbacks.add(() => { }, [() => { }], () => { }); + + // $ExpectType Callbacks + callbacks.add(() => { }, [() => { }]); + + // $ExpectType Callbacks + callbacks.add(() => { }, () => { }); + + // $ExpectType Callbacks + callbacks.add(() => { }); + + // $ExpectType Callbacks + callbacks.add([() => { }]); + } + + function disable() { + // $ExpectType Callbacks + $.Callbacks().disable(); + } + + function disabled() { + // $ExpectType boolean + $.Callbacks().disabled(); + } + + function empty() { + // $ExpectType Callbacks + $.Callbacks().empty(); + } + + function fire() { + // $ExpectType Callbacks + $.Callbacks().fire(1); + + // $ExpectType Callbacks + $.Callbacks().fire(); + } + + function fireWith() { + // $ExpectType Callbacks + $.Callbacks().fireWith(window, [1]); + + // $ExpectType Callbacks + $.Callbacks().fireWith(window); + } + + function fired() { + // $ExpectType boolean + $.Callbacks().fired(); + } + + function has() { + // $ExpectType boolean + $.Callbacks().has(() => { }); + + // $ExpectType boolean + $.Callbacks().has(); + } + + function lock() { + // $ExpectType Callbacks + $.Callbacks().lock(); + } + + function locked() { + // $ExpectType boolean + $.Callbacks().locked(); + } + + function remove() { + // $ExpectType Callbacks + $.Callbacks().remove(() => { }, () => { }); + } +} + function EffectsOptions() { $('p').show({ always(animation, jumpToEnd) { @@ -4593,51 +5098,272 @@ function EffectsOptions() { }); } -function JQuery_Event() { - function mixin() { - const e = $.Event('keydown', { - mySpecialKeyCode: JQuery.Key.CapsLock, - }); +function _Event() { + function call_signature() { + // $ExpectType Event & Coordinates + $.Event('keydown', $('p').offset()); - e.mySpecialKeyCode === JQuery.Key.NumLock; + // $ExpectType Event & { type: string; } + $.Event({ + type: 'keydown' + }); + } + + function constructor() { + // $ExpectType Event & Coordinates + new $.Event('keydown', $('p').offset()); + + // $ExpectType Event & { type: string; } + new $.Event({ + type: 'keydown' + }); } } function jqXHR() { - function catch_returnType() { - // $ExpectType Deferred - $.ajax('/echo').catch(() => { }); - } - - function catch_throw_returnType() { - // $ExpectType Deferred - $.ajax('/echo').catch((reason) => { - throw new Error(); - }); - } - - function then_returnType() { - // $ExpectType Deferred - $.ajax('/echo').then(() => { }); - } - - function throw_from_catch() { - $.ajax('/echo').catch(() => { - throw new Error('Thrown from [jQuery] 1st catch block'); - }).then((value) => { - // $ExpectType never - value; - }).catch((reason) => { + function always() { + // $ExpectType jqXHR + $.ajax('/echo/json').always((data_jqXHR, textStatus, jqXHR_errorThrown) => { // $ExpectType any - reason; - }).then((value) => { - // $ExpectType void - value; + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }, [(data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }], (data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; }); + + // $ExpectType jqXHR + $.ajax('/echo/json').always((data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }, [(data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }]); + + // $ExpectType jqXHR + $.ajax('/echo/json').always([(data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }], (data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').always((data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').always([(data_jqXHR, textStatus, jqXHR_errorThrown) => { + // $ExpectType any + data_jqXHR; + // $ExpectType TextStatus + textStatus; + // $ExpectType string | jqXHR + jqXHR_errorThrown; + }]); + } + + function done() { + // $ExpectType jqXHR + $.ajax('/echo/json').done((data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, [(data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }], (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').done((data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, [(data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }]); + + // $ExpectType jqXHR + $.ajax('/echo/json').done([(data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }], (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').done((data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').done([(data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }]); } function fail() { - $.ajax('/echo').fail((jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + $.ajax('/echo/json').fail((jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }, [(jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }], (jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').fail((jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }, [(jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }]); + + // $ExpectType jqXHR + $.ajax('/echo/json').fail([(jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }], (jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').fail((jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }); + + // $ExpectType jqXHR + $.ajax('/echo/json').fail([(jqXHR, textStatus, errorThrown) => { + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }]); + } + + function _catch() { + // $ExpectType Promise3 + $.ajax('/echo').catch((jqXHR, textStatus, errorThrown) => { // $ExpectType jqXHR jqXHR; // $ExpectType ErrorTextStatus @@ -4647,3 +5373,625 @@ function jqXHR() { }); } } + +function Promise3() { + interface I1 { kind: 'I1'; } + interface I2 { kind: 'I2'; } + interface I3 { kind: 'I3'; } + interface I4 { kind: 'I4'; } + interface I5 { kind: 'I5'; } + interface I6 { kind: 'I6'; } + interface I7 { kind: 'I7'; } + interface I8 { kind: 'I8'; } + interface I9 { kind: 'I9'; } + + const p: JQuery.Promise3 = {} as any; + const p1: JQuery.Promise3 = {} as any; + const p2: JQuery.Promise3 = {} as any; + const p3: JQuery.Promise3 = {} as any; + + const t1: JQuery.Thenable = {} as any; + const t2: JQuery.Thenable = {} as any; + const t3: JQuery.Thenable = {} as any; + + function then() { + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + + p.then(null, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, null, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + + p.then(null, null, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, null); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }); + + p.then(null, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, null); + + p.then(null, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, null, null); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, null); + + p.then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }); + + function doneFilter() { + p.then(() => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(() => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(() => { + return p; + }).then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + } + + function failFilter() { + p.then(null, () => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(null, () => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(null, () => { + return p; + }).then((a, b, c) => { + a; // $ExpectType string + b; // $ExpectType JQuery + c; // $ExpectType any + }, (a, b, c) => { + a; // $ExpectType Error + b; // $ExpectType string + c; // $ExpectType Function + }, (a, b, c) => { + a; // $ExpectType number + b; // $ExpectType boolean + c; // $ExpectType never + }); + } + + function doneFilter_failFilter() { + // (value, value) + { + const q = p.then(() => { + return 1; + }, () => { + return 1; + }); + + q.then((a) => { + a; // $ExpectType number + }, (a) => { + a; // $ExpectType never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // (Thenable, Thenable) + { + const q = p.then(() => { + return t1; + }, () => { + return t2; + }); + + q.then((a) => { + a; // $ExpectType I1 | I2 + }, (a) => { + a; // $ExpectType never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // (Promise3, Promise3) + { + const q = p.then(() => { + return p1; + }, () => { + return p2; + }); + + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I4 | I5 + c; // $ExpectType I7 | I8 + }, (a, b, c) => { + a; // $ExpectType I2 | I3 + b; // $ExpectType I5 | I6 + c; // $ExpectType I8 | I9 + }, (a, b, c) => { + a; // $ExpectType I3 | I4 + b; // $ExpectType I6 | I7 + c; // $ExpectType I1 | I9 + }); + } + + // (value, Thenable) + { + const q = p.then(() => { + return 1; + }, () => { + return t1; + }); + + q.then((a) => { + a; // $ExpectType number | I1 + }, (a) => { + a; // never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // (Thenable, value) + { + const q = p.then(() => { + return t1; + }, () => { + return 1; + }); + + q.then((a) => { + a; // $ExpectType number | I1 + }, (a) => { + a; // never + }, (a, b, c) => { + a; // $ExpectType never + b; // $ExpectType never + c; // $ExpectType never + }); + } + + // (value, Promise3) + { + const q = p.then(() => { + return 1; + }, () => { + return p1; + }); + + q.then((a, b, c) => { + a; // $ExpectType number | I1 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } + + // (Promise3, value) + { + const q = p.then(() => { + return p1; + }, () => { + return 1; + }); + + q.then((a, b, c) => { + a; // $ExpectType number | I1 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } + + // (Thenable, Promise3) + { + const q = p.then(() => { + return t1; + }, () => { + return p2; + }); + + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }, (a, b, c) => { + a; // $ExpectType I4 + b; // $ExpectType I7 + c; // $ExpectType I1 + }); + } + + // (Promise3, Thenable) + { + const q = p.then(() => { + return p1; + }, () => { + return t2; + }); + + q.then((a, b, c) => { + a; // $ExpectType I1 | I2 + b; // $ExpectType I4 + c; // $ExpectType I7 + }, (a, b, c) => { + a; // $ExpectType I2 + b; // $ExpectType I5 + c; // $ExpectType I8 + }, (a, b, c) => { + a; // $ExpectType I3 + b; // $ExpectType I6 + c; // $ExpectType I9 + }); + } + } + } + + function _catch() { + // $ExpectType Promise3 + $.ajax('/echo/json').catch(() => { + return 1; + }); + + // $ExpectType Promise3 + $.ajax('/echo/json').catch(() => { + return t1; + }); + + // $ExpectType Promise3, never, SuccessTextStatus, ErrorTextStatus, never, jqXHR, string, never> + $.ajax('/echo/json').catch(() => { + return $.ajax('/echo/json'); + }); + } +} + +function Promise2(p: JQuery.Promise2) { + function then() { + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + + p.then(null, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, null, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + + p.then(null, null, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, null); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }); + + p.then(null, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, null); + + p.then(null, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, null, null); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, null); + + p.then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }); + + function doneFilter() { + p.then(() => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(() => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(() => { + return p; + }).then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + } + + function failFilter() { + p.then(null, () => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(null, () => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(null, () => { + return p; + }).then((a, b) => { + a; // $ExpectType string + b; // $ExpectType JQuery + }, (a, b) => { + a; // $ExpectType Error + b; // $ExpectType string + }, (a, b) => { + a; // $ExpectType number + b; // $ExpectType boolean + }); + } + } +} + +function _Promise(p: JQuery.Promise) { + function then() { + p.then((a) => { + a; // $ExpectType string + }, (a) => { + a; // $ExpectType Error + }, (a) => { + a; // $ExpectType number + }); + + p.then(null, (a) => { + a; // $ExpectType Error + }, (a) => { + a; // $ExpectType number + }); + + p.then((a) => { + a; // $ExpectType string + }, null, (a) => { + a; // $ExpectType number + }); + + p.then(null, null, (a) => { + a; // $ExpectType number + }); + + p.then((a) => { + a; // $ExpectType string + }, (a) => { + a; // $ExpectType Error + }, null); + + p.then((a) => { + a; // $ExpectType string + }, (a) => { + a; // $ExpectType Error + }); + + p.then(null, (a) => { + a; // $ExpectType Error + }, null); + + p.then(null, (a) => { + a; // $ExpectType Error + }); + + p.then((a) => { + a; // $ExpectType string + }, null, null); + + p.then((a) => { + a; // $ExpectType string + }, null); + + p.then((a) => { + a; // $ExpectType string + }); + + function doneFilter() { + p.then(() => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(() => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(() => { + return p; + }).then((a) => { + a; // $ExpectType string + }, (a) => { + a; // $ExpectType Error + }, (a) => { + a; // $ExpectType number + }); + } + + function failFilter() { + p.then(null, () => { + return 1; + }).then((a) => { + a; // $ExpectType number + }); + + p.then(null, () => { + return $.ready; + }).then((a) => { + a; // $ExpectType JQueryStatic + }); + + p.then(null, () => { + return p; + }).then((a) => { + a; // $ExpectType string + }, (a) => { + a; // $ExpectType Error + }, (a) => { + a; // $ExpectType number + }); + } + } +} diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 404aba2013..0c871de0a7 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -1202,14 +1202,13 @@ function examples() { // Attach a done, fail, and progress handler for the asyncEvent $.when(asyncEvent()).then( function(status) { - status === 3; alert(status + ', things are going well'); }, function(status) { alert(status + ', you fail this time'); }, function(status) { - // $('body').append(status); + $('body').append(status); }, ); } @@ -1233,9 +1232,7 @@ function examples() { // Use the object as a Promise _obj.done(function(name) { _obj.hello(name); // Will alert "Hello John" - }); - /// TODO: This doesn't work even though .done() returns this - // .hello('Karl'); // Will alert "Hello Karl" + }).hello('Karl'); // Will alert "Hello Karl" } function deferred_then_0() { @@ -1392,7 +1389,7 @@ function examples() { function each_2() { $('button').click(function() { $('div').each(function(index, element) { - // element == this + // element == this; $(element).css('backgroundColor', 'yellow'); if ($(this).is('#stop')) { $('span').text('Stopped at div index #' + index); @@ -3757,13 +3754,13 @@ function examples() { function offset_0() { var p = $('p:last'); - var offset = p.offset(); + var offset = p.offset()!; p.html('left: ' + offset.left + ', top: ' + offset.top); } function offset_1() { $('*', document.body).click(function(event) { - var offset = $(this).offset(); + var offset = $(this).offset()!; event.stopPropagation(); $('#result').text(this.tagName + ' coords ( ' + offset.left + ', ' + offset.top + ' )'); diff --git a/types/jquery/tslint.json b/types/jquery/tslint.json index 401b7a77e9..ca514c4aba 100644 --- a/types/jquery/tslint.json +++ b/types/jquery/tslint.json @@ -2,8 +2,9 @@ "extends": "dtslint/dt.json", "rules": { "ban-types": false, - "no-misused-new": false, + "callable-types": false, "no-empty-interface": false, - "callable-types": false + "no-misused-new": false, + "space-before-function-paren": false } }