diff --git a/types/ace/index.d.ts b/types/ace/index.d.ts index 90466c946e..58bf1c2bd8 100644 --- a/types/ace/index.d.ts +++ b/types/ace/index.d.ts @@ -474,7 +474,9 @@ declare namespace AceAjax { removeFold(arg: any): void; expandFold(arg: any): void; - + + foldAll(startRow?: number, endRow?: number, depth?: number): void + unfold(arg1: any, arg2: boolean): void; screenToDocumentColumn(row: number, column: number): void; diff --git a/types/angular-animate/index.d.ts b/types/angular-animate/index.d.ts index 7e3202bc0e..0ce96a2f2f 100644 --- a/types/angular-animate/index.d.ts +++ b/types/angular-animate/index.d.ts @@ -2,9 +2,7 @@ // Project: http://angularjs.org // Definitions by: Michel Salib , Adi Dahiya , Raphael Schweizer , Cody Schaaf // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 - -/// +// TypeScript Version: 2.1 declare var _: string; export = _; diff --git a/types/angular-local-storage/angular-local-storage-tests.ts b/types/angular-local-storage/angular-local-storage-tests.ts index ead14e85fb..b3fdde8b9e 100644 --- a/types/angular-local-storage/angular-local-storage-tests.ts +++ b/types/angular-local-storage/angular-local-storage-tests.ts @@ -64,6 +64,7 @@ app.config(function (localStorageServiceProvider: ng.local.storage.ILocalStorage localStorageServiceProvider .setPrefix('myApp') .setStorageType('sessionStorage') + .setDefaultToCookie(false) .setNotify(true, true); }); diff --git a/types/angular-local-storage/index.d.ts b/types/angular-local-storage/index.d.ts index faa99065da..76ab65b1b5 100644 --- a/types/angular-local-storage/index.d.ts +++ b/types/angular-local-storage/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for angular-local-storage v0.1.6 +// Type definitions for angular-local-storage v0.6.0 // Project: https://github.com/grevory/angular-local-storage -// Definitions by: Ken Fukuyama +// Definitions by: Ken Fukuyama , Davide Donadello // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -27,12 +27,18 @@ declare module 'angular' { * @param storageType localstorage or sessionStorage. default: localStorage */ setStorageType(storageType: string): ILocalStorageServiceProvider; + /** + * If localStorage is not supported, the library will default to cookies instead. This behavior can be disabled + * @param shouldDefault default: true + */ + setDefaultToCookie(shouldDefault: boolean): ILocalStorageServiceProvider; /** * Setter for cookie config * @param exp number of days before cookies expire (0 = does not expire). default: 30 * @param path the web path the cookie represents. default: '/' + * @param secure to store cookies as secure. default: false */ - setStorageCookie(exp: number, path: string): ILocalStorageServiceProvider; + setStorageCookie(exp: number, path: string, secure: boolean): ILocalStorageServiceProvider; /** * Set the cookie domain, since this runs inside a the config() block, only providers and constants can be injected. As a result, $location service can't be used here, use a hardcoded string or window.location. * No default value diff --git a/types/angular/angular-tests.ts b/types/angular/angular-tests.ts index 80b73c062a..6a601910d0 100644 --- a/types/angular/angular-tests.ts +++ b/types/angular/angular-tests.ts @@ -178,7 +178,7 @@ mod.controller({ mod.directive('myDirectiveA', ($rootScope: ng.IRootScopeService) => { return (scope, el, attrs) => { let foo = 'none'; - el.click(e => { + el.on('click', e => { foo = e.type; $rootScope.$apply(); }); @@ -188,8 +188,9 @@ mod.directive('myDirectiveA', ($rootScope: ng.IRootScopeService) => { mod.directive('myDirectiveB', ['$rootScope', ($rootScope: ng.IRootScopeService) => { return { link(scope, el, attrs) { - el.click(e => { - el.hide(); + el.on('click', e => { + // Doesn't exist on jqLite + // el.hide(); }); } }; @@ -1017,13 +1018,13 @@ angular.module('multiSlotTranscludeExample', []) }, link(scope, element, attrs, ctrl, transclude) { // without scope - transclude().appendTo(element); - transclude(clone => clone.appendTo(element)); + element.append(transclude()); + transclude(clone => element.append(clone)); // with scope - transclude(scope, clone => clone.appendTo(element)); - transclude(scope, clone => clone.appendTo(element), element, 'button'); - transclude(scope, null, element, 'list').addClass('drop-down-list').appendTo(element); + transclude(scope, clone => element.append(clone)); + transclude(scope, clone => element.append(clone), element, 'button'); + element.append(transclude(scope, null, element, 'list').addClass('drop-down-list')); } }; }); diff --git a/types/angular/index.d.ts b/types/angular/index.d.ts index fe78ba03ff..4f8d55f9dc 100644 --- a/types/angular/index.d.ts +++ b/types/angular/index.d.ts @@ -4,7 +4,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -/// +/// declare var angular: angular.IAngularStatic; @@ -2116,22 +2116,3 @@ declare namespace angular { (obj: Object): string; } } - -declare global { - interface JQuery { - // TODO: events, how to define? - // $destroy - - find(element: any): JQuery; - find(obj: JQuery): JQuery; - controller(name?: string): any; - injector(): ng.auto.IInjectorService; - /** It's declared generic for custom scope interfaces */ - scope(): T; - isolateScope(): T; - - inheritedData(key: string, value: any): JQuery; - inheritedData(obj: { [key: string]: any; }): JQuery; - inheritedData(key?: string): any; - } -} diff --git a/types/angular/jqlite.d.ts b/types/angular/jqlite.d.ts new file mode 100644 index 0000000000..36509143fa --- /dev/null +++ b/types/angular/jqlite.d.ts @@ -0,0 +1,802 @@ +// Definitions by: Boris Yankov +// Christian Hoffmeister +// Steve Fenton +// Diullei Gomes +// Tass Iliopoulos +// Jason Swearingen +// Sean Hill +// Guus Goossens +// Kelly Summerlin +// Basarat Ali Syed +// Nicholas Wolverson +// Derek Cicerone +// Andrew Gaspar +// Seikichi Kondo +// Benjamin Jackman +// Poul Sorensen +// Josh Strobl +// John Reilly +// Dick van den Brink +// Thomas Schulz +// Leonard Thieu + +// Definitions copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0480c5ec87fab41aa23047a02b27f0ea71aaf975/types/jquery/v2/index.d.ts + +interface JQuery { + /** + * Adds the specified class(es) to each of the set of matched elements. + * + * @param className One or more space-separated classes to be added to the class attribute of each matched element. + * @see {@link https://api.jquery.com/addClass/#addClass-className} + */ + addClass(className: string): JQuery; + + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * @param content1 HTML string, DOM element, DocumentFragment, array of elements, or jQuery object to insert after each element in the set of matched elements. + * @param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert after each element in the set of matched elements. + * @see {@link https://api.jquery.com/after/#after-content-content} + */ + after(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, after each element in the set of matched elements. + * + * @param func A function that returns an HTML string, DOM element(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. + * @see {@link https://api.jquery.com/after/#after-function} + */ + after(func: (index: number, html: string) => string | Element | JQuery): JQuery; + + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * @param content1 DOM element, DocumentFragment, array of elements, HTML string, or jQuery object to insert at the end of each element in the set of matched elements. + * @param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the end of each element in the set of matched elements. + * @see {@link https://api.jquery.com/append/#append-content-content} + */ + append(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the end of each element in the set of matched elements. + * + * @param func A function that returns an HTML string, DOM element(s), or jQuery object to insert at the end of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set. + * @see {@link https://api.jquery.com/append/#append-function} + */ + append(func: (index: number, html: string) => string | Element | JQuery): JQuery; + + /** + * Get the value of an attribute for the first element in the set of matched elements. + * + * @param attributeName The name of the attribute to get. + * @see {@link https://api.jquery.com/attr/#attr-attributeName} + */ + attr(attributeName: string): string; + /** + * Set one or more attributes for the set of matched elements. + * + * @param attributeName The name of the attribute to set. + * @param value A value to set for the attribute. If this is `null`, the attribute will be deleted. + * @see {@link https://api.jquery.com/attr/#attr-attributeName-value} + */ + attr(attributeName: string, value: string | number | null): JQuery; + /** + * Set one or more attributes for the set of matched elements. + * + * @param attributes An object of attribute-value pairs to set. + * @see {@link https://api.jquery.com/attr/#attr-attributes} + */ + attr(attributes: Object): JQuery; + + /** + * Attach a handler to an event for the elements. + * + * @param eventType A string containing one or more DOM event types, such as "click" or "submit," or custom event names. + * @param handler A function to execute each time the event is triggered. + * @see {@link https://api.jquery.com/bind/#bind-eventType-eventData-handler} + */ + bind(eventType: string, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Attach a handler to an event for the elements. + * + * @param eventType A string containing one or more DOM event types, such as "click" or "submit," or custom event names. + * @param preventBubble Setting the third argument to false will attach a function that prevents the default action from occurring and stops the event from bubbling. The default is true. + * @see {@link https://api.jquery.com/bind/#bind-eventType-eventData-preventBubble} + */ + bind(eventType: string, preventBubble: boolean): JQuery; + /** + * Attach a handler to an event for the elements. + * + * @param events An object containing one or more DOM event types and functions to execute for them. + * @see {@link https://api.jquery.com/bind/#bind-events} + */ + bind(events: any): JQuery; + + /** + * Get the children of each element in the set of matched elements, optionally filtered by a selector. + * + * @see {@link https://api.jquery.com/children/} + */ + children(): JQuery; + + /** + * Create a deep copy of the set of matched elements. + * + * @param withDataAndEvents A Boolean indicating whether event handlers and data should be copied along with the elements. The default value is false. + * @param deepWithDataAndEvents A Boolean indicating whether event handlers and data for all children of the cloned element should be copied. By default its value matches the first argument's value (which defaults to false). + * @see {@link https://api.jquery.com/clone/} + */ + clone(withDataAndEvents?: boolean, deepWithDataAndEvents?: boolean): JQuery; + + /** + * Get the children of each element in the set of matched elements, including text and comment nodes. + * @see {@link https://api.jquery.com/contents/} + */ + contents(): JQuery; + + /** + * Get the value of style properties for the first element in the set of matched elements. + * + * @param propertyName A CSS property. + * @see {@link https://api.jquery.com/css/#css-propertyName} + */ + css(propertyName: string): string; + /** + * Get the value of style properties for the first element in the set of matched elements. + * Results in an object of property-value pairs. + * + * @param propertyNames An array of one or more CSS properties. + * @see {@link https://api.jquery.com/css/#css-propertyNames} + */ + css(propertyNames: string[]): any; + /** + * Set one or more CSS properties for the set of matched elements. + * + * @param propertyName A CSS property name. + * @param value A value to set for the property. + * @see {@link https://api.jquery.com/css/#css-propertyName-value} + */ + css(propertyName: string, value: string | number): JQuery; + /** + * Set one or more CSS properties for the set of matched elements. + * + * @param propertyName A CSS property name. + * @param value A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old value as arguments. + * @see {@link https://api.jquery.com/css/#css-propertyName-function} + */ + css(propertyName: string, value: (index: number, value: string) => string | number): JQuery; + /** + * Set one or more CSS properties for the set of matched elements. + * + * @param properties An object of property-value pairs to set. + * @see {@link https://api.jquery.com/css/#css-properties} + */ + css(properties: JQueryCssProperties): JQuery; + + /** + * Store arbitrary data associated with the matched elements. + * + * @param key A string naming the piece of data to set. + * @param value The new data value; it can be any JavaScript type including Array or Object. + * @see {@link https://api.jquery.com/data/#data-key-value} + */ + data(key: string, value: any): JQuery; + /** + * Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute. + * + * @param key Name of the data stored. + * @see {@link https://api.jquery.com/data/#data-key} + */ + data(key: string): any; + /** + * Store arbitrary data associated with the matched elements. + * + * @param obj An object of key-value pairs of data to update. + * @see {@link https://api.jquery.com/data/#data-obj} + */ + data(obj: { [key: string]: any; }): JQuery; + /** + * Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute. + * @see {@link https://api.jquery.com/data/#data} + */ + data(): any; + + /** + * Remove the set of matched elements from the DOM. + * + * @param selector A selector expression that filters the set of matched elements to be removed. + * @see {@link https://api.jquery.com/detach/} + */ + detach(selector?: string): JQuery; + + /** + * Remove all child nodes of the set of matched elements from the DOM. + * @see {@link https://api.jquery.com/empty/} + */ + empty(): JQuery; + + /** + * Reduce the set of matched elements to the one at the specified index. + * + * @param index An integer indicating the 0-based position of the element. OR An integer indicating the position of the element, counting backwards from the last element in the set. + * @see {@link https://api.jquery.com/eq/} + */ + eq(index: number): JQuery; + + /** + * Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element. + * + * @param selector A string containing a selector expression to match elements against. + * @see {@link https://api.jquery.com/find/#find-selector} + */ + find(selector: string): JQuery; + find(element: any): JQuery; + find(obj: JQuery): JQuery; + + /** + * Determine whether any of the matched elements are assigned the given class. + * + * @param className The class name to search for. + * @see {@link https://api.jquery.com/hasClass/} + */ + hasClass(className: string): boolean; + + /** + * Get the HTML contents of the first element in the set of matched elements. + * @see {@link https://api.jquery.com/html/#html} + */ + html(): string; + /** + * Set the HTML contents of each element in the set of matched elements. + * + * @param htmlString A string of HTML to set as the content of each matched element. + * @see {@link https://api.jquery.com/html/#html-htmlString} + */ + html(htmlString: string): JQuery; + /** + * Set the HTML contents of each element in the set of matched elements. + * + * @param func A function returning the HTML content to set. Receives the index position of the element in the set and the old HTML value as arguments. jQuery empties the element before calling the function; use the oldhtml argument to reference the previous content. Within the function, this refers to the current element in the set. + * @see {@link https://api.jquery.com/html/#html-function} + */ + html(func: (index: number, oldhtml: string) => string): JQuery; + + /** + * Get the immediately following sibling of each element in the set of matched elements. If a selector is provided, it retrieves the next sibling only if it matches that selector. + * + * @see {@link https://api.jquery.com/next/} + */ + next(): JQuery; + + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. Rest parameter args is for optional parameters passed to jQuery.trigger(). Note that the actual parameters on the event handler function must be marked as optional (? syntax). + * @see {@link https://api.jquery.com/on/#on-events-selector-data-handler} + */ + on(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. + * @see {@link https://api.jquery.com/on/#on-events-selector-data-handler} + */ + on(events: string, data: any, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. + * @see {@link https://api.jquery.com/on/#on-events-selector-data-handler} + */ + on(events: string, selector: string, handler: (eventObject: JQueryEventObject, ...eventData: any[]) => any): JQuery; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. + * @see {@link https://api.jquery.com/on/#on-events-selector-data-handler} + */ + on(events: string, selector: string, data: any, handler: (eventObject: JQueryEventObject, ...eventData: any[]) => any): JQuery; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s). + * @param selector A selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see {@link https://api.jquery.com/on/#on-events-selector-data} + */ + on(events: { [key: string]: (eventObject: JQueryEventObject, ...args: any[]) => any; }, selector?: string, data?: any): JQuery; + /** + * Attach an event handler function for one or more events to the selected elements. + * + * @param events An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s). + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see {@link https://api.jquery.com/on/#on-events-selector-data} + */ + on(events: { [key: string]: (eventObject: JQueryEventObject, ...args: any[]) => any; }, data?: any): JQuery; + + /** + * Remove an event handler. + * @see {@link https://api.jquery.com/off/#off} + */ + off(): JQuery; + /** + * Remove an event handler. + * + * @param events One or more space-separated event types and optional namespaces, or just namespaces, such as "click", "keydown.myPlugin", or ".myPlugin". + * @param selector A selector which should match the one originally passed to .on() when attaching event handlers. + * @param handler A handler function previously attached for the event(s), or the special value false. + * @see {@link https://api.jquery.com/off/#off-events-selector-handler} + */ + off(events: string, selector?: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Remove an event handler. + * + * @param events One or more space-separated event types and optional namespaces, or just namespaces, such as "click", "keydown.myPlugin", or ".myPlugin". + * @param handler A handler function previously attached for the event(s), or the special value false. Takes handler with extra args that can be attached with on(). + * @see {@link https://api.jquery.com/off/#off-events-selector-handler} + */ + off(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): JQuery; + /** + * Remove an event handler. + * + * @param events One or more space-separated event types and optional namespaces, or just namespaces, such as "click", "keydown.myPlugin", or ".myPlugin". + * @param handler A handler function previously attached for the event(s), or the special value false. + * @see {@link https://api.jquery.com/off/#off-events-selector-handler} + */ + off(events: string, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Remove an event handler. + * + * @param events An object where the string keys represent one or more space-separated event types and optional namespaces, and the values represent handler functions previously attached for the event(s). + * @param selector A selector which should match the one originally passed to .on() when attaching event handlers. + * @see {@link https://api.jquery.com/off/#off-events-selector} + */ + off(events: { [key: string]: any; }, selector?: string): JQuery; + + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events A string containing one or more JavaScript event types, such as "click" or "submit," or custom event names. + * @param handler A function to execute at the time the event is triggered. + * @see {@link https://api.jquery.com/one/#one-events-data-handler} + */ + one(events: string, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events A string containing one or more JavaScript event types, such as "click" or "submit," or custom event names. + * @param data An object containing data that will be passed to the event handler. + * @param handler A function to execute at the time the event is triggered. + * @see {@link https://api.jquery.com/one/#one-events-data-handler} + */ + one(events: string, data: Object, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. + * @see {@link https://api.jquery.com/one/#one-events-selector-data-handler} + */ + one(events: string, selector: string, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events One or more space-separated event types and optional namespaces, such as "click" or "keydown.myPlugin". + * @param selector A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event is triggered. + * @param handler A function to execute when the event is triggered. The value false is also allowed as a shorthand for a function that simply does return false. + * @see {@link https://api.jquery.com/one/#one-events-selector-data-handler} + */ + one(events: string, selector: string, data: any, handler: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s). + * @param selector A selector string to filter the descendants of the selected elements that will call the handler. If the selector is null or omitted, the handler is always called when it reaches the selected element. + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see {@link https://api.jquery.com/one/#one-events-selector-data} + */ + one(events: { [key: string]: any; }, selector?: string, data?: any): JQuery; + /** + * Attach a handler to an event for the elements. The handler is executed at most once per element per event type. + * + * @param events An object in which the string keys represent one or more space-separated event types and optional namespaces, and the values represent a handler function to be called for the event(s). + * @param data Data to be passed to the handler in event.data when an event occurs. + * @see {@link https://api.jquery.com/one/#one-events-selector-data} + */ + one(events: { [key: string]: any; }, data?: any): JQuery; + + /** + * Get the parent of each element in the current set of matched elements, optionally filtered by a selector. + * + * @see {@link https://api.jquery.com/parent/} + */ + parent(): JQuery; + + /** + * Insert content, specified by the parameter, to the beginning of each element in the set of matched elements. + * + * @param content1 DOM element, DocumentFragment, array of elements, HTML string, or jQuery object to insert at the beginning of each element in the set of matched elements. + * @param content2 One or more additional DOM elements, arrays of elements, HTML strings, or jQuery objects to insert at the beginning of each element in the set of matched elements. + * @see {@link https://api.jquery.com/prepend/#prepend-content-content} + */ + prepend(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): JQuery; + /** + * Insert content, specified by the parameter, to the beginning of each element in the set of matched elements. + * + * @param func A function that returns an HTML string, DOM element(s), or jQuery object to insert at the beginning of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set. + * @see {@link https://api.jquery.com/prepend/#prepend-function} + */ + prepend(func: (index: number, html: string) => string | Element | JQuery): JQuery; + + /** + * Get the value of a property for the first element in the set of matched elements. + * + * @param propertyName The name of the property to get. + * @see {@link https://api.jquery.com/prop/#prop-propertyName} + */ + prop(propertyName: string): any; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param value A value to set for the property. + * @see {@link https://api.jquery.com/prop/#prop-propertyName-value} + */ + prop(propertyName: string, value: string | number | boolean): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param properties An object of property-value pairs to set. + * @see {@link https://api.jquery.com/prop/#prop-properties} + */ + prop(properties: Object): JQuery; + /** + * Set one or more properties for the set of matched elements. + * + * @param propertyName The name of the property to set. + * @param func A function returning the value to set. Receives the index position of the element in the set and the old property value as arguments. Within the function, the keyword this refers to the current element. + * @see {@link https://api.jquery.com/prop/#prop-propertyName-function} + */ + prop(propertyName: string, func: (index: number, oldPropertyValue: any) => any): JQuery; + + /** + * Specify a function to execute when the DOM is fully loaded. + * + * @param handler A function to execute after the DOM is ready. + * @see {@link https://api.jquery.com/ready/} + */ + ready(handler: (jQueryAlias?: JQueryStatic) => any): JQuery; + + /** + * Remove the set of matched elements from the DOM. + * + * @param selector A selector expression that filters the set of matched elements to be removed. + * @see {@link https://api.jquery.com/remove/} + */ + remove(selector?: string): JQuery; + + /** + * Remove an attribute from each element in the set of matched elements. + * + * @param attributeName An attribute to remove; as of version 1.7, it can be a space-separated list of attributes. + * @see {@link https://api.jquery.com/removeAttr/} + */ + removeAttr(attributeName: string): JQuery; + + /** + * Remove a single class, multiple classes, or all classes from each element in the set of matched elements. + * + * @param className One or more space-separated classes to be removed from the class attribute of each matched element. + * @see {@link https://api.jquery.com/removeClass/#removeClass-className} + */ + removeClass(className?: string): JQuery; + + /** + * Remove a previously-stored piece of data. + * + * @param name A string naming the piece of data to delete or space-separated string naming the pieces of data to delete. + * @see {@link https://api.jquery.com/removeData/#removeData-name} + */ + removeData(name: string): JQuery; + /** + * Remove a previously-stored piece of data. + * + * @param list An array of strings naming the pieces of data to delete. + * @see {@link https://api.jquery.com/removeData/#removeData-list} + */ + removeData(list: string[]): JQuery; + /** + * Remove all previously-stored piece of data. + * @see {@link https://api.jquery.com/removeData/} + */ + removeData(): JQuery; + + /** + * Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed. + * + * @param newContent The content to insert. May be an HTML string, DOM element, array of DOM elements, or jQuery object. + * @see {@link https://api.jquery.com/replaceWith/#replaceWith-newContent} + */ + replaceWith(newContent: JQuery | any[] | Element | Text | string): JQuery; + /** + * Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed. + * + * @param func A function that returns content with which to replace the set of matched elements. + * @see {@link https://api.jquery.com/replaceWith/#replaceWith-function} + */ + replaceWith(func: () => Element | JQuery): JQuery; + + /** + * Get the combined text contents of each element in the set of matched elements, including their descendants. + * @see {@link https://api.jquery.com/text/#text} + */ + text(): string; + /** + * Set the content of each element in the set of matched elements to the specified text. + * + * @param text The text to set as the content of each matched element. When Number or Boolean is supplied, it will be converted to a String representation. + * @see {@link https://api.jquery.com/text/#text-text} + */ + text(text: string | number | boolean): JQuery; + /** + * Set the content of each element in the set of matched elements to the specified text. + * + * @param func A function returning the text content to set. Receives the index position of the element in the set and the old text value as arguments. + * @see {@link https://api.jquery.com/text/#text-function} + */ + text(func: (index: number, text: string) => string): JQuery; + + /** + * Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument. + * + * @param className One or more class names (separated by spaces) to be toggled for each element in the matched set. + * @param swtch A Boolean (not just truthy/falsy) value to determine whether the class should be added or removed. + * @see {@link https://api.jquery.com/toggleClass/#toggleClass-className} + */ + toggleClass(className: string, swtch?: boolean): JQuery; + /** + * Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument. + * + * @param swtch A boolean value to determine whether the class should be added or removed. + * @see {@link https://api.jquery.com/toggleClass/#toggleClass-state} + */ + toggleClass(swtch?: boolean): JQuery; + + /** + * Execute all handlers attached to an element for an event. + * + * @param eventType A string containing a JavaScript event type, such as click or submit. + * @param extraParameters An array of additional parameters to pass along to the event handler. + * @see {@link https://api.jquery.com/triggerHandler/#triggerHandler-eventType-extraParameters} + */ + triggerHandler(eventType: string, ...extraParameters: any[]): Object; + /** + * Execute all handlers attached to an element for an event. + * + * @param event A jQuery.Event object. + * @param extraParameters An array of additional parameters to pass along to the event handler. + * @see {@link https://api.jquery.com/triggerHandler/#triggerHandler-event-extraParameters} + */ + triggerHandler(event: JQueryEventObject, ...extraParameters: any[]): Object; + + /** + * Remove a previously-attached event handler from the elements. + * + * @param eventType A string containing a JavaScript event type, such as click or submit. + * @param handler The function that is to be no longer executed. + * @see {@link https://api.jquery.com/unbind/#unbind-eventType-handler} + */ + unbind(eventType?: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; + /** + * Remove a previously-attached event handler from the elements. + * + * @param eventType A string containing a JavaScript event type, such as click or submit. + * @param fls Unbinds the corresponding 'return false' function that was bound using .bind( eventType, false ). + * @see {@link https://api.jquery.com/unbind/#unbind-eventType-false} + */ + unbind(eventType: string, fls: boolean): JQuery; + /** + * Remove a previously-attached event handler from the elements. + * + * @param evt A JavaScript event object as passed to an event handler. + * @see {@link https://api.jquery.com/unbind/#unbind-event} + */ + unbind(evt: any): JQuery; + + /** + * Get the current value of the first element in the set of matched elements. + * @see {@link https://api.jquery.com/val/#val} + */ + val(): any; + /** + * Set the value of each element in the set of matched elements. + * + * @param value A string of text, an array of strings or number corresponding to the value of each matched element to set as selected/checked. + * @see {@link https://api.jquery.com/val/#val-value} + */ + val(value: string | string[] | number): JQuery; + /** + * Set the value of each element in the set of matched elements. + * + * @param func A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old value as arguments. + * @see {@link https://api.jquery.com/val/#val-function} + */ + val(func: (index: number, value: string) => string): JQuery; + + /** + * Wrap an HTML structure around each element in the set of matched elements. + * + * @param wrappingElement A selector, element, HTML string, or jQuery object specifying the structure to wrap around the matched elements. + * @see {@link https://api.jquery.com/wrap/#wrap-wrappingElement} + */ + wrap(wrappingElement: JQuery | Element | string): JQuery; + /** + * Wrap an HTML structure around each element in the set of matched elements. + * + * @param func A callback function returning the HTML content or jQuery object to wrap around the matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. + * @see {@link https://api.jquery.com/wrap/#wrap-function} + */ + wrap(func: (index: number) => string | JQuery): JQuery; + + // Undocumented + length: number; + + // TODO: events, how to define? + // $destroy + + controller(name?: string): any; + injector(): ng.auto.IInjectorService; + /** It's declared generic for custom scope interfaces */ + scope(): T; + isolateScope(): T; + + inheritedData(key: string, value: any): JQuery; + inheritedData(obj: { [key: string]: any; }): JQuery; + inheritedData(key?: string): any; +} + +interface JQueryStatic { + (element: string | Element): JQuery; +} + +/** + * Interface of the JQuery extension of the W3C event object + * @see {@link https://api.jquery.com/category/events/event-object/} + */ +interface BaseJQueryEventObject extends Event { + /** + * The current DOM element within the event bubbling phase. + * @see {@link https://api.jquery.com/event.currentTarget/} + */ + currentTarget: Element; + /** + * 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/} + */ + data: any; + /** + * The element where the currently-called jQuery event handler was attached. + * @see {@link https://api.jquery.com/event.delegateTarget/} + */ + delegateTarget: Element; + /** + * Returns whether event.preventDefault() was ever called on this event object. + * @see {@link https://api.jquery.com/event.isDefaultPrevented/} + */ + isDefaultPrevented(): boolean; + /** + * Returns whether event.stopImmediatePropagation() was ever called on this event object. + * @see {@link https://api.jquery.com/event.isImmediatePropagationStopped/} + */ + isImmediatePropagationStopped(): boolean; + /** + * Returns whether event.stopPropagation() was ever called on this event object. + * @see {@link https://api.jquery.com/event.isPropagationStopped/} + */ + isPropagationStopped(): boolean; + /** + * The namespace specified when the event was triggered. + * @see {@link https://api.jquery.com/event.namespace/} + */ + namespace: string; + /** + * The browser's original Event object. + * @see {@link https://api.jquery.com/category/events/event-object/} + */ + originalEvent: Event; + /** + * If this method is called, the default action of the event will not be triggered. + * @see {@link https://api.jquery.com/event.preventDefault/} + */ + preventDefault(): any; + /** + * The other DOM element involved in the event, if any. + * @see {@link https://api.jquery.com/event.relatedTarget/} + */ + relatedTarget: Element; + /** + * The last value returned by an event handler that was triggered by this event, unless the value was undefined. + * @see {@link https://api.jquery.com/event.result/} + */ + result: any; + /** + * Keeps the rest of the handlers from being executed and prevents the event from bubbling up the DOM tree. + * @see {@link https://api.jquery.com/event.stopImmediatePropagation/} + */ + stopImmediatePropagation(): void; + /** + * Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. + * @see {@link https://api.jquery.com/event.stopPropagation/} + */ + stopPropagation(): void; + /** + * The DOM element that initiated the event. + * @see {@link https://api.jquery.com/event.target/} + */ + target: Element; + /** + * The mouse position relative to the left edge of the document. + * @see {@link https://api.jquery.com/event.pageX/} + */ + pageX: number; + /** + * The mouse position relative to the top edge of the document. + * @see {@link https://api.jquery.com/event.pageY/} + */ + pageY: number; + /** + * For key or mouse events, this property indicates the specific key or button that was pressed. + * @see {@link https://api.jquery.com/event.which/} + */ + which: number; + /** + * Indicates whether the META key was pressed when the event fired. + * @see {@link https://api.jquery.com/event.metaKey/} + */ + metaKey: boolean; +} + +interface JQueryInputEventObject extends BaseJQueryEventObject { + altKey: boolean; + ctrlKey: boolean; + metaKey: boolean; + shiftKey: boolean; +} + +interface JQueryMouseEventObject extends JQueryInputEventObject { + button: number; + clientX: number; + clientY: number; + offsetX: number; + offsetY: number; + pageX: number; + pageY: number; + screenX: number; + screenY: number; +} + +interface JQueryKeyEventObject extends JQueryInputEventObject { + char: any; + charCode: number; + key: any; + keyCode: number; +} + +interface JQueryEventObject extends BaseJQueryEventObject, JQueryInputEventObject, JQueryMouseEventObject, JQueryKeyEventObject { +} + +/** + * The interface used to specify the properties parameter in css() + */ +type cssPropertySetter = (index: number, value?: string) => string | number; +interface JQueryCssProperties { + [propertyName: string]: string | number | cssPropertySetter; +} diff --git a/types/angular/test/jquery3-merging-tests.ts b/types/angular/test/jquery3-merging-tests.ts new file mode 100644 index 0000000000..0dbe37f640 --- /dev/null +++ b/types/angular/test/jquery3-merging-tests.ts @@ -0,0 +1,456 @@ +import * as $ from 'jquery'; +import * as angular from 'angular'; + +function JQuery() { + function addClass() { + // $ExpectType JQuery + $('p').addClass('className'); + + // $ExpectType JQuery + $('p').addClass(function(index, currentClassName) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + currentClassName; + + return 'className'; + }); + } + + function attr() { + // $ExpectType JQuery + $('#greatphoto').attr('alt', 'Beijing Brush Seller'); + + // $ExpectType JQuery + $('#greatphoto').attr('width', 200); + + // $ExpectType JQuery + $('#greatphoto').attr('title', null); + + // $ExpectType JQuery + $('#greatphoto').attr('alt', function(index, attr) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + attr; + + return 'Beijing Brush Seller'; + }); + + // $ExpectType JQuery + $('#greatphoto').attr('width', function(index, attr) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + attr; + + return 200; + }); + + // $ExpectType JQuery + $('#greatphoto').attr('title', function(index, attr) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + attr; + }); + + // $ExpectType JQuery + $('#greatphoto').attr('title', function(index, attr) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + attr; + + return undefined; + }); + + // $ExpectType JQuery + $('img').attr({ + src: '/resources/hat.gif', + title: 'jQuery', + alt: 'jQuery Logo' + }); + + // $ExpectType string + $('img').attr('src'); + } + + function bind() { + // $ExpectType JQuery + $('p').bind('myEvent', 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('p').bind('myEvent', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('p').bind('myEvent', false); + + // $ExpectType JQuery + $('p').bind({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + }, + myEvent2: false + }); + + // $ExpectType JQuery + $('p').bind('myEvent', null); + + // $ExpectType JQuery + $('p').bind('myEvent', undefined); + } + + function children() { + $('p').children(); + + $('p').children('span'); + } + + function off() { + // $ExpectType JQuery + $('table').off('myEvent', 'td', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').off('myEvent', 'td', false); + + // $ExpectType JQuery + $('table').off('myEvent', 'td'); + + // $ExpectType JQuery + $('table').off('myEvent', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').off('myEvent', false); + + // $ExpectType JQuery + $('table').off('myEvent'); + + // $ExpectType JQuery + $('table').off({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 'td'); + + // $ExpectType JQuery + $('table').off({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }); + + // $ExpectType JQuery + $('table').off($.Event('myEvent')); + + // $ExpectType JQuery + $('table').off(); + } + + function on() { + // $ExpectType JQuery + $('table').on('myEvent', 'td', 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', null, 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', 'td', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', 'td', false); + + // $ExpectType JQuery + $('table').on('myEvent', 3, function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').on('myEvent', false); + + // $ExpectType JQuery + $('table').on({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 'td', 'myData'); + + // $ExpectType JQuery + $('table').on({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, null, 'myData'); + + // $ExpectType JQuery + $('table').on({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 'td'); + + // $ExpectType JQuery + $('table').on({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 3); + + // $ExpectType JQuery + $('table').on({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }); + } + + function one() { + // $ExpectType JQuery + $('table').one('myEvent', 'td', 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', null, 'myData', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', 'td', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', 'td', false); + + // $ExpectType JQuery + $('table').one('myEvent', 3, function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', function(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }); + + // $ExpectType JQuery + $('table').one('myEvent', false); + + // $ExpectType JQuery + $('table').one({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 'td', 'myData'); + + // $ExpectType JQuery + $('table').one({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, null, 'myData'); + + // $ExpectType JQuery + $('table').one({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 'td'); + + // $ExpectType JQuery + $('table').one({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }, 3); + + // $ExpectType JQuery + $('table').one({ + myEvent1(event) { + // $ExpectType HTMLElement + this; + // $ExpectType Event + event; + }, + myEvent2: false + }); + } + + function removeClass() { + // $ExpectType JQuery + $('p').removeClass('className'); + + // $ExpectType JQuery + $('p').removeClass(function(index, currentClassName) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + currentClassName; + + return 'className'; + }); + + // $ExpectType JQuery + $('p').removeClass(); + } + + function toggleClass() { + // $ExpectType JQuery + $('p').toggleClass('className', true); + + // $ExpectType JQuery + $('p').toggleClass(function(index, className, state) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + className; + // $ExpectType true + state; + + return 'className'; + }, true); + + // $ExpectType JQuery + $('p').toggleClass('className'); + + // $ExpectType JQuery + $('p').toggleClass(function(index, className, state) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + className; + // $ExpectType boolean + state; + + return 'className'; + }); + + // $ExpectType JQuery + $('p').toggleClass(false); + + // $ExpectType JQuery + $('p').toggleClass(); + } +} diff --git a/types/angular/tsconfig.json b/types/angular/tsconfig.json index 860cc82f22..33c9531cab 100644 --- a/types/angular/tsconfig.json +++ b/types/angular/tsconfig.json @@ -1,13 +1,16 @@ { "files": [ "index.d.ts", - "angular-tests.ts" + "jqlite.d.ts", + "angular-tests.ts", + "test/jquery3-merging-tests.ts" ], "compilerOptions": { "module": "commonjs", "lib": [ - "es6", - "dom" + "es5", + "dom", + "es2015.iterable" ], "noImplicitAny": false, "noImplicitThis": false, @@ -20,4 +23,4 @@ "noEmit": true, "forceConsistentCasingInFileNames": true } -} \ No newline at end of file +} diff --git a/types/bluebird/bluebird-tests.ts b/types/bluebird/bluebird-tests.ts index e616ae3f85..8aef9daa66 100644 --- a/types/bluebird/bluebird-tests.ts +++ b/types/bluebird/bluebird-tests.ts @@ -576,7 +576,6 @@ barProm = fooArrProm.spread((one: Foo, two: Bar, twotwo: Foo) => { //TODO fix collection inference barArrProm = fooProm.all(); -objProm = fooProm.props(); fooInspectionPromise = fooProm.reflect(); barProm = fooProm.any(); barArrProm = fooProm.some(num); @@ -584,6 +583,17 @@ barProm = fooProm.race(); // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +var propsValue: { num: number, str: string }; +Promise.resolve({ num: 1, str: Promise.resolve('a') }).props().then(val => { propsValue = val }); +Promise.props({ num: 1, str: Promise.resolve('a') }).then(val => { propsValue = val }); +Promise.props(Promise.props({ num: 1, str: Promise.resolve('a') })).then(val => { propsValue = val }); + +var propsMapValue: Map; +Promise.resolve(new Map>()).props().then(val => { propsMapValue = val }); +Promise.props(new Map>()).then(val => { propsMapValue = val }); + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Promise.all([fooProm, barProm]).then(result => { result[0].foo(); result[1].bar(); diff --git a/types/bluebird/index.d.ts b/types/bluebird/index.d.ts index 8482e5fe6e..844dad53d4 100644 --- a/types/bluebird/index.d.ts +++ b/types/bluebird/index.d.ts @@ -620,8 +620,8 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { /** * Same as calling `Promise.props(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. */ - // TODO how to model instance.props()? - props(): Bluebird; + props(this: PromiseLike | V>>): Bluebird>; + props(this: PromiseLike>): Bluebird; /** * Same as calling `Promise.any(thisPromise)`. With the exception that if this promise is bound to a value, the returned promise is bound to that value too. @@ -806,11 +806,13 @@ declare class Bluebird implements PromiseLike, Bluebird.Inspection { * * *The original object is not modified.* */ - // TODO verify this is correct // trusted promise for object - static props(object: Bluebird): Bluebird; + static props(map: PromiseLike | V>>): Bluebird>; + static props(object: PromiseLike>): Bluebird; + // map + static props(map: Map | V>): Bluebird>; // object - static props(object: Object): Bluebird; + static props(object: Bluebird.ResolvableProps): Bluebird; /** * Like `Promise.some()`, with 1 as `count`. However, if the promise fulfills, the fulfillment value is not an array of 1 but the value directly. @@ -1074,6 +1076,8 @@ declare namespace Bluebird { /** @deprecated Use PromiseLike directly. */ export type Thenable = PromiseLike; + export type ResolvableProps = object & { [K in keyof T]: PromiseLike | T[K] }; + export interface Resolver { /** * Returns a reference to the controlled promise that can be passed to clients. diff --git a/types/core-js/index.d.ts b/types/core-js/index.d.ts index 9593bc7a76..0a8f506df4 100644 --- a/types/core-js/index.d.ts +++ b/types/core-js/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for core-js 0.9 // Project: https://github.com/zloirock/core-js/ -// Definitions by: Ron Buckton +// Definitions by: Ron Buckton , Michel Felipe // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.1 @@ -50,7 +50,10 @@ declare function $for(iterable: Iterable): $for; // ECMAScript 7 // Modules: es7.array.includes, es7.string.at, es7.string.pad-start, es7.string.pad-end, // es7.object.to-array, es7.object.get-own-property-descriptors, es7.regexp.escape, -// es7.map.to-json, and es7.set.to-json +// es7.map.to-json, es7.set.to-json, es7.reflect.define-metadata, es7.reflect.delete-metadata +// es7.reflect.get-metadata, es7.reflect.get-metadata-keys, es7.reflect.get-own-metadata, +// es7.reflect.get-own-metadata-keys, es7.reflect.has-metadata, es7.reflect.has-own-metadata +// es7.reflect.metadata // ############################################################################################# interface String { @@ -473,6 +476,202 @@ declare namespace core { function preventExtensions(target: any): boolean; function set(target: any, propertyKey: PropertyKey, value: any, receiver?: any): boolean; function setPrototypeOf(target: any, proto: any): boolean; + /** + * Define a unique metadata entry on the target. + * @param metadataKey A key used to store and retrieve metadata. + * @param metadataValue A value that contains attached metadata. + * @param target The target object on which to define metadata. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * Reflect.defineMetadata("custom:annotation", options, Example); + * + * // decorator factory as metadata-producing annotation. + * function MyAnnotation(options): ClassDecorator { + * return target => Reflect.defineMetadata("custom:annotation", options, target); + * } + * ``` + */ + function defineMetadata(metadataKey: any, metadataValue: any, target: Object, targetKey?: string | symbol): void; + /** + * Deletes the metadata entry from the target object with the provided key. + * @param metadataKey A key used to store and retrieve metadata. + * @param target The target object on which the metadata is defined. + * @returns `true` if the metadata entry was found and deleted; otherwise, false. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.deleteMetadata("custom:annotation", Example); + * ``` + */ + function deleteMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean; + /** + * Gets the metadata value for the provided metadata key on the target object or its prototype chain. + * @param metadataKey A key used to store and retrieve metadata. + * @param target The target object on which the metadata is defined. + * @returns The metadata value for the metadata key if found; otherwise, `undefined`. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.getMetadata("custom:annotation", Example); + * ``` + */ + function getMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): any; + /** + * Gets the metadata keys defined on the target object or its prototype chain. + * @param target The target object on which the metadata is defined. + * @returns An array of unique metadata keys. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.getMetadataKeys(Example); + * ``` + */ + function getMetadataKeys(target: Object, targetKey?: string | symbol): any[]; + /** + * Gets the metadata value for the provided metadata key on the target object. + * @param metadataKey A key used to store and retrieve metadata. + * @param target The target object on which the metadata is defined. + * @returns The metadata value for the metadata key if found; otherwise, `undefined`. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.getOwnMetadata("custom:annotation", Example); + * ``` + */ + function getOwnMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): any; + + /** + * Gets the unique metadata keys defined on the target object. + * @param target The target object on which the metadata is defined. + * @returns An array of unique metadata keys. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.getOwnMetadataKeys(Example); + * ``` + */ + function getOwnMetadataKeys(target: Object, targetKey?: string | symbol): any[]; + /** + * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined. + * @param metadataKey A key used to store and retrieve metadata. + * @param target The target object on which the metadata is defined. + * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`. + * @example + * + * ### Example + * + * ```typescript + * class Example { + * } + * + * // constructor + * result = Reflect.hasMetadata("custom:annotation", Example); + * ``` + */ + function hasMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean; + /** + * Gets a value indicating whether the target object has the provided metadata key defined. + * @param metadataKey A key used to store and retrieve metadata. + * @param target The target object on which the metadata is defined. + * @returns `true` if the metadata key was defined on the target object; otherwise, `false`. + * @example + * + * ### Example + * + * ```typescript + * + * class Example { + * } + * + * // constructor + * result = Reflect.hasOwnMetadata("custom:annotation", Example); + * ``` + */ + function hasOwnMetadata(metadataKey: any, target: Object, targetKey?: string | symbol): boolean; + /** + * A default metadata decorator factory that can be used on a class, class member, or parameter. + * @param metadataKey The key for the metadata entry. + * @param metadataValue The value for the metadata entry. + * @returns A decorator function. + * @remarks + * If `metadataKey` is already defined for the target and target key, the + * metadataValue for that key will be overwritten. + * @example + * + * ### Example + * + * ```typescript + * // constructor + * @Reflect.metadata(key, value) + * class Example { + * } + * + * // property (on constructor, TypeScript only) + * class Example { + * @Reflect.metadata(key, value) + * static staticProperty; + * } + * + * // property (on prototype, TypeScript only) + * class Example { + * @Reflect.metadata(key, value) + * property; + * } + * + * // method (on constructor) + * class Example { + * @Reflect.metadata(key, value) + * static staticMethod() { } + * } + * + * // method (on prototype) + * class Example { + * @Reflect.metadata(key, value) + * method() { } + * } + * ``` + */ + function metadata(metadataKey: any, metadataValue: any): { + (target: Function): void; + (target: Object, targetKey: string | symbol): void; + }; } const Object: { @@ -1991,6 +2190,42 @@ declare module "core-js/library/fn/reflect/set-prototype-of" { const setPrototypeOf: typeof core.Reflect.setPrototypeOf; export = setPrototypeOf; } +declare module "core-js/library/fn/reflect/es7/define-metadata" { + const defineMetadata: typeof core.Reflect.defineMetadata; + export = defineMetadata; +} +declare module "core-js/library/fn/reflect/es7/delete-metadata" { + const deleteMetadata: typeof core.Reflect.deleteMetadata; + export = deleteMetadata; +} +declare module "core-js/library/fn/reflect/es7/get-metadata" { + const getMetadata: typeof core.Reflect.getMetadata; + export = getMetadata; +} +declare module "core-js/library/fn/reflect/es7/get-metadata-keys" { + const getMetadataKeys: typeof core.Reflect.getMetadataKeys; + export = getMetadataKeys; +} +declare module "core-js/library/fn/reflect/es7/get-own-metadata" { + const getOwnMetadata: typeof core.Reflect.getOwnMetadata; + export = getOwnMetadata; +} +declare module "core-js/library/fn/reflect/es7/get-own-metadata-keys'" { + const getOwnMetadataKeys: typeof core.Reflect.getOwnMetadataKeys; + export = getOwnMetadataKeys; +} +declare module "core-js/library/fn/reflect/es7/has-metadata'" { + const hasMetadata: typeof core.Reflect.hasMetadata; + export = hasMetadata; +} +declare module "core-js/library/fn/reflect/es7/has-own-metadata'" { + const hasOwnMetadata: typeof core.Reflect.hasOwnMetadata; + export = hasOwnMetadata; +} +declare module "core-js/library/fn/reflect/es7/metadata'" { + const metadata: typeof core.Reflect.metadata; + export = metadata; +} declare module "core-js/library/fn/regexp" { const RegExp: typeof core.RegExp; export = RegExp; diff --git a/types/draft-js/index.d.ts b/types/draft-js/index.d.ts index a3c14b73b4..f7f389ea33 100644 --- a/types/draft-js/index.d.ts +++ b/types/draft-js/index.d.ts @@ -54,7 +54,7 @@ declare namespace Draft { * These props are analagous to `value` and `onChange` in controlled React * text inputs. */ - interface DraftEditorProps { + export interface DraftEditorProps { editorState: EditorState; onChange(editorState: EditorState): void; diff --git a/types/elasticsearch/index.d.ts b/types/elasticsearch/index.d.ts index a0606a4961..34be61f5b0 100644 --- a/types/elasticsearch/index.d.ts +++ b/types/elasticsearch/index.d.ts @@ -13,75 +13,75 @@ declare module Elasticsearch { nodes: Nodes; snapshot: Snapshot; tasks: Tasks; - bulk(params: BulkIndexDocumentsParams): PromiseLike; + bulk(params: BulkIndexDocumentsParams): Promise; bulk(params: BulkIndexDocumentsParams, callback: (error: any, response: any) => void): void; clearScroll(params: ClearScrollParams, callback: (error: any, response: any) => void): void; - clearScroll(params: ClearScrollParams): PromiseLike; + clearScroll(params: ClearScrollParams): Promise; count(params: CountParams, callback: (error: any, response: CountResponse) => void): void; - count(params: CountParams): PromiseLike; - create(params: CreateDocumentParams): PromiseLike; + count(params: CountParams): Promise; + create(params: CreateDocumentParams): Promise; create(params: CreateDocumentParams, callback: (err: any, response: CreateDocumentResponse, status: any) => void): void; - delete(params: DeleteDocumentParams): PromiseLike; + delete(params: DeleteDocumentParams): Promise; delete(params: DeleteDocumentParams, callback: (error: any, response: DeleteDocumentResponse) => void): void; - deleteByQuery(params: DeleteDocumentByQueryParams): PromiseLike; + deleteByQuery(params: DeleteDocumentByQueryParams): Promise; deleteByQuery(params: DeleteDocumentByQueryParams, callback: (error: any, response: DeleteDocumentByQueryResponse) => void): void; - deleteScript(params: DeleteScriptParams): PromiseLike; + deleteScript(params: DeleteScriptParams): Promise; deleteScript(params: DeleteScriptParams, callback: (error: any, response: any) => void): void; - deleteTemplate(params: DeleteTemplateParams): PromiseLike; + deleteTemplate(params: DeleteTemplateParams): Promise; deleteTemplate(params: DeleteTemplateParams, callback: (error: any, response: any) => void): void; - exists(params: ExistsParams): PromiseLike; + exists(params: ExistsParams): Promise; exists(params: ExistsParams, callback: (error: any, response: any, status?: any) => void): void; - explain(params: ExplainParams): PromiseLike; + explain(params: ExplainParams): Promise; explain(params: ExplainParams, callback: (error: any, response: ExplainResponse) => void): void; - fieldStats(params: FieldStatsParams): PromiseLike; + fieldStats(params: FieldStatsParams): Promise; fieldStats(params: FieldStatsParams, callback: (error: any, response: FieldStatsResponse) => void): void; get(params: GetParams, callback: (error: any, response: GetResponse) => void): void; - get(params: GetParams): PromiseLike>; - getScript(params: GetScriptParams): PromiseLike; + get(params: GetParams): Promise>; + getScript(params: GetScriptParams): Promise; getScript(params: GetScriptParams, callback: (error: any, response: any) => void): void; - getSource(params: GetSourceParams): PromiseLike; + getSource(params: GetSourceParams): Promise; getSource(params: GetSourceParams, callback: (error: any, response: any) => void): void; - getTemplate(params: GetTemplateParams): PromiseLike; + getTemplate(params: GetTemplateParams): Promise; getTemplate(params: GetTemplateParams, callback: (error: any, response: any) => void): void; - index(params: IndexDocumentParams): PromiseLike; + index(params: IndexDocumentParams): Promise; index(params: IndexDocumentParams, callback: (error: any, response: any) => void): void; - info(params: InfoParams): PromiseLike; + info(params: InfoParams): Promise; info(params: InfoParams, callback: (error: any, response: any) => void): void; mget(params: MGetParams, callback: (error: any, response: MGetResponse) => void): void; - mget(params: MGetParams): PromiseLike>; + mget(params: MGetParams): Promise>; msearch(params: MSearchParams, callback: (error: any, response: MSearchResponse) => void): void; - msearch(params: MSearchParams): PromiseLike>; + msearch(params: MSearchParams): Promise>; msearchTemplate(params: MSearchTemplateParams, callback: (error: any, response: MSearchResponse) => void): void; - msearchTemplate(params: MSearchTemplateParams): PromiseLike>; - mtermvectors(params: MTermVectorsParams): PromiseLike; + msearchTemplate(params: MSearchTemplateParams): Promise>; + mtermvectors(params: MTermVectorsParams): Promise; mtermvectors(params: MTermVectorsParams, callback: (error: any, response: any) => void): void; - ping(params: PingParams): PromiseLike; + ping(params: PingParams): Promise; ping(params: PingParams, callback: (err: any, response: any, status: any) => void): void; - putScript(params: PutScriptParams): PromiseLike; + putScript(params: PutScriptParams): Promise; putScript(params: PutScriptParams, callback: (err: any, response: any, status: any) => void): void; - putTemplate(params: PutTemplateParams): PromiseLike; + putTemplate(params: PutTemplateParams): Promise; putTemplate(params: PutTemplateParams, callback: (err: any, response: any, status: any) => void): void; - reindex(params: ReindexParams): PromiseLike; + reindex(params: ReindexParams): Promise; reindex(params: ReindexParams, callback: (error: any, response: ReindexResponse) => void): void; - reindexRethrottle(params: ReindexRethrottleParams): PromiseLike; + reindexRethrottle(params: ReindexRethrottleParams): Promise; reindexRethrottle(params: ReindexRethrottleParams, callback: (error: any, response: any) => void): void; - renderSearchTemplate(params: RenderSearchTemplateParams): PromiseLike; + renderSearchTemplate(params: RenderSearchTemplateParams): Promise; renderSearchTemplate(params: RenderSearchTemplateParams, callback: (error: any, response: any) => void): void; - scroll(params: ScrollParams): PromiseLike; - scroll(params: ScrollParams, callback: (error: any, response: any) => void): void; - search(params: SearchParams): PromiseLike>; + scroll(params: ScrollParams): Promise>; + scroll(params: ScrollParams, callback: (error: any, response: SearchResponse) => void): void; + search(params: SearchParams): Promise>; search(params: SearchParams, callback: (error: any, response: SearchResponse) => void): void; - searchShards(params: SearchShardsParams): PromiseLike; + searchShards(params: SearchShardsParams): Promise; searchShards(params: SearchShardsParams, callback: (error: any, response: SearchShardsResponse) => void): void; - searchTemplate(params: SearchTemplateParams): PromiseLike; + searchTemplate(params: SearchTemplateParams): Promise; searchTemplate(params: SearchTemplateParams, callback: (error: any, response: any) => void): void; - suggest(params: SuggestParams): PromiseLike; + suggest(params: SuggestParams): Promise; suggest(params: SuggestParams, callback: (error: any, response: any) => void): void; - termvectors(params: TermvectorsParams): PromiseLike; + termvectors(params: TermvectorsParams): Promise; termvectors(params: TermvectorsParams, callback: (error: any, response: any) => void): void; - update(params: UpdateDocumentParams): PromiseLike; + update(params: UpdateDocumentParams): Promise; update(params: UpdateDocumentParams, callback: (error: any, response: any) => void): void; - updateByQuery(params: UpdateDocumentByQueryParams): PromiseLike; + updateByQuery(params: UpdateDocumentByQueryParams): Promise; updateByQuery(params: UpdateDocumentByQueryParams, callback: (error: any, response: any) => void): void; } @@ -774,43 +774,43 @@ declare module Elasticsearch { export interface Cat { aliases(params: CatAliasesParams, callback: (error: any, response: any) => void): void; - aliases(params: CatAliasesParams): PromiseLike; + aliases(params: CatAliasesParams): Promise; allocation(params: CatAllocationParams, callback: (error: any, response: any) => void): void; - allocation(params: CatAllocationParams): PromiseLike; + allocation(params: CatAllocationParams): Promise; count(params: CatCountParams, callback: (error: any, response: any) => void): void; - count(params: CatAllocationParams): PromiseLike; + count(params: CatAllocationParams): Promise; fielddata(params: CatFielddataParams, callback: (error: any, response: any) => void): void; - fielddata(params: CatFielddataParams): PromiseLike; + fielddata(params: CatFielddataParams): Promise; health(params: CatHealthParams, callback: (error: any, response: any) => void): void; - health(params: CatHealthParams): PromiseLike; + health(params: CatHealthParams): Promise; help(params: CatHelpParams, callback: (error: any, response: any) => void): void; - help(params: CatHelpParams): PromiseLike; + help(params: CatHelpParams): Promise; indices(params: CatIndicesParams, callback: (error: any, response: any) => void): void; - indices(params: CatIndicesParams): PromiseLike; + indices(params: CatIndicesParams): Promise; master(params: CatCommonParams, callback: (error: any, response: any) => void): void; - master(params: CatCommonParams): PromiseLike; + master(params: CatCommonParams): Promise; nodeattrs(params: CatCommonParams, callback: (error: any, response: any) => void): void; - nodeattrs(params: CatCommonParams): PromiseLike; + nodeattrs(params: CatCommonParams): Promise; nodes(params: CatCommonParams, callback: (error: any, response: any) => void): void; - nodes(params: CatCommonParams): PromiseLike; + nodes(params: CatCommonParams): Promise; pendingTasks(params: CatCommonParams, callback: (error: any, response: any) => void): void; - pendingTasks(params: CatCommonParams): PromiseLike; + pendingTasks(params: CatCommonParams): Promise; plugins(params: CatCommonParams, callback: (error: any, response: any) => void): void; - plugins(params: CatCommonParams): PromiseLike; + plugins(params: CatCommonParams): Promise; recovery(params: CatRecoveryParams, callback: (error: any, response: any) => void): void; - recovery(params: CatRecoveryParams): PromiseLike; + recovery(params: CatRecoveryParams): Promise; repositories(params: CatCommonParams, callback: (error: any, response: any) => void): void; - repositories(params: CatCommonParams): PromiseLike; + repositories(params: CatCommonParams): Promise; segments(params: CatSegmentsParams, callback: (error: any, response: any) => void): void; - segments(params: CatSegmentsParams): PromiseLike; + segments(params: CatSegmentsParams): Promise; shards(params: CatShardsParams, callback: (error: any, response: any) => void): void; - shards(params: CatShardsParams): PromiseLike; + shards(params: CatShardsParams): Promise; snapshots(params: CatSnapshotsParams, callback: (error: any, response: any) => void): void; - snapshots(params: CatSnapshotsParams): PromiseLike; + snapshots(params: CatSnapshotsParams): Promise; tasks(params: CatTasksParams, callback: (error: any, response: any) => void): void; - tasks(params: CatTasksParams): PromiseLike; + tasks(params: CatTasksParams): Promise; threadPool(params: CatThreadPoolParams, callback: (error: any, response: any) => void): void; - threadPool(params: CatThreadPoolParams): PromiseLike; + threadPool(params: CatThreadPoolParams): Promise; } export type CatBytes = "b" | "k" | "kb" | "m" | "mb" | "g" | "gb" | "t" | "tb" | "p" | "pb"; @@ -907,21 +907,21 @@ declare module Elasticsearch { export interface Cluster { allocationExplain(params: ClusterAllocationExplainParams, callback: (error: any, response: any) => void): void; - allocationExplain(params: ClusterAllocationExplainParams): PromiseLike; + allocationExplain(params: ClusterAllocationExplainParams): Promise; getSettings(params: ClusterGetSettingsParams, callback: (error: any, response: any) => void): void; - getSettings(params: ClusterGetSettingsParams): PromiseLike; + getSettings(params: ClusterGetSettingsParams): Promise; health(params: ClusterHealthParams, callback: (error: any, response: any) => void): void; - health(params: ClusterHealthParams): PromiseLike; + health(params: ClusterHealthParams): Promise; pendingTasks(params: ClusterPendingTasksParams, callback: (error: any, response: any) => void): void; - pendingTasks(params: ClusterPendingTasksParams): PromiseLike; + pendingTasks(params: ClusterPendingTasksParams): Promise; putSettings(params: ClusterPutSettingsParams, callback: (error: any, response: any) => void): void; - putSettings(params: ClusterPutSettingsParams): PromiseLike; + putSettings(params: ClusterPutSettingsParams): Promise; reroute(params: ClusterRerouteParams, callback: (error: any, response: any) => void): void; - reroute(params: ClusterRerouteParams): PromiseLike; + reroute(params: ClusterRerouteParams): Promise; state(params: ClusterStateParams, callback: (error: any, response: any) => void): void; - state(params: ClusterStateParams): PromiseLike; + state(params: ClusterStateParams): Promise; stats(params: ClusterStatsParams, callback: (error: any, response: any) => void): void; - stats(params: ClusterStatsParams): PromiseLike; + stats(params: ClusterStatsParams): Promise; } export interface ClusterAllocationExplainParams extends GenericParams { @@ -988,77 +988,77 @@ declare module Elasticsearch { export class Indices { analyze(params: IndicesAnalyzeParams, callback: (error: any, response: any, status: any) => void): void; - analyze(params: IndicesAnalyzeParams): PromiseLike; + analyze(params: IndicesAnalyzeParams): Promise; clearCache(params: IndicesClearCacheParams, callback: (error: any, response: any, status: any) => void): void; - clearCache(params: IndicesClearCacheParams): PromiseLike; + clearCache(params: IndicesClearCacheParams): Promise; close(params: IndicesCloseParams, callback: (error: any, response: any, status: any) => void): void; - close(params: IndicesCloseParams): PromiseLike; + close(params: IndicesCloseParams): Promise; create(params: IndicesCreateParams, callback: (error: any, response: any, status: any) => void): void; - create(params: IndicesCreateParams): PromiseLike; + create(params: IndicesCreateParams): Promise; delete(params: IndicesDeleteParams, callback: (error: any, response: any, status: any) => void): void; - delete(params: IndicesDeleteParams): PromiseLike; + delete(params: IndicesDeleteParams): Promise; deleteAlias(params: IndicesDeleteAliasParams, callback: (error: any, response: any, status: any) => void): void; - deleteAlias(params: IndicesDeleteAliasParams): PromiseLike; + deleteAlias(params: IndicesDeleteAliasParams): Promise; deleteTemplate(params: IndicesDeleteTemplateParams, callback: (error: any, response: any, status: any) => void): void; - deleteTemplate(params: IndicesDeleteTemplateParams): PromiseLike; + deleteTemplate(params: IndicesDeleteTemplateParams): Promise; exists(params: IndicesExistsParams, callback: (error: any, response: any, status: any) => void): void; - exists(params: IndicesExistsParams): PromiseLike; + exists(params: IndicesExistsParams): Promise; existsAlias(params: IndicesExistsAliasParams, callback: (error: any, response: any, status: any) => void): void; - existsAlias(params: IndicesExistsAliasParams): PromiseLike; + existsAlias(params: IndicesExistsAliasParams): Promise; existsTemplate(params: IndicesExistsTemplateParams, callback: (error: any, response: any, status: any) => void): void; - existsTemplate(params: IndicesExistsTemplateParams): PromiseLike; + existsTemplate(params: IndicesExistsTemplateParams): Promise; existsType(params: IndicesExistsTypeParams, callback: (error: any, response: any, status: any) => void): void; - existsType(params: IndicesExistsTypeParams): PromiseLike; + existsType(params: IndicesExistsTypeParams): Promise; flush(params: IndicesFlushParams, callback: (error: any, response: any, status: any) => void): void; - flush(params: IndicesFlushParams): PromiseLike; + flush(params: IndicesFlushParams): Promise; flushSynced(params: IndicesFlushSyncedParams, callback: (error: any, response: any, status: any) => void): void; - flushSynced(params: IndicesFlushSyncedParams): PromiseLike; + flushSynced(params: IndicesFlushSyncedParams): Promise; forcemerge(params: IndicesForcemergeParams, callback: (error: any, response: any, status: any) => void): void; - forcemerge(params: IndicesForcemergeParams): PromiseLike; + forcemerge(params: IndicesForcemergeParams): Promise; get(params: IndicesGetParams, callback: (error: any, response: any, status: any) => void): void; - get(params: IndicesGetParams): PromiseLike; + get(params: IndicesGetParams): Promise; getAlias(params: IndicesGetAliasParams, callback: (error: any, response: any, status: any) => void): void; - getAlias(params: IndicesGetAliasParams): PromiseLike; + getAlias(params: IndicesGetAliasParams): Promise; getFieldMapping(params: IndicesGetFieldMappingParams, callback: (error: any, response: any, status: any) => void): void; - getFieldMapping(params: IndicesGetFieldMappingParams): PromiseLike; + getFieldMapping(params: IndicesGetFieldMappingParams): Promise; getMapping(params: IndicesGetMappingParams, callback: (error: any, response: any, status: any) => void): void; - getMapping(params: IndicesGetMappingParams): PromiseLike; + getMapping(params: IndicesGetMappingParams): Promise; getSettings(params: IndicesGetSettingsParams, callback: (error: any, response: any, status: any) => void): void; - getSettings(params: IndicesGetSettingsParams): PromiseLike; + getSettings(params: IndicesGetSettingsParams): Promise; getTemplate(params: IndicesGetTemplateParams, callback: (error: any, response: any, status: any) => void): void; - getTemplate(params: IndicesGetTemplateParams): PromiseLike; + getTemplate(params: IndicesGetTemplateParams): Promise; getUpgrade(params: IndicesGetUpgradeParams, callback: (error: any, response: any, status: any) => void): void; - getUpgrade(params: IndicesGetUpgradeParams): PromiseLike; + getUpgrade(params: IndicesGetUpgradeParams): Promise; open(params: IndicesOpenParams, callback: (error: any, response: any, status: any) => void): void; - open(params: IndicesOpenParams): PromiseLike; + open(params: IndicesOpenParams): Promise; putAlias(params: IndicesPutAliasParams, callback: (error: any, response: any, status: any) => void): void; - putAlias(params: IndicesPutAliasParams): PromiseLike; + putAlias(params: IndicesPutAliasParams): Promise; putMapping(params: IndicesPutMappingParams, callback: (error: any, response: any, status: any) => void): void; - putMapping(params: IndicesPutMappingParams): PromiseLike; + putMapping(params: IndicesPutMappingParams): Promise; putSettings(params: IndicesPutSettingsParams, callback: (error: any, response: any, status: any) => void): void; - putSettings(params: IndicesPutSettingsParams): PromiseLike; + putSettings(params: IndicesPutSettingsParams): Promise; putTemplate(params: IndicesPutTemplateParams, callback: (error: any, response: any) => void): void; - putTemplate(params: IndicesPutTemplateParams): PromiseLike; + putTemplate(params: IndicesPutTemplateParams): Promise; recovery(params: IndicesRecoveryParams, callback: (error: any, response: any) => void): void; - recovery(params: IndicesRecoveryParams): PromiseLike; + recovery(params: IndicesRecoveryParams): Promise; refresh(params: IndicesRefreshParams, callback: (error: any, response: any) => void): void; - refresh(params: IndicesRefreshParams): PromiseLike; + refresh(params: IndicesRefreshParams): Promise; rollover(params: IndicesRolloverParams, callback: (error: any, response: IndicesRolloverResponse) => void): void; - rollover(params: IndicesRolloverParams): PromiseLike; + rollover(params: IndicesRolloverParams): Promise; segments(params: IndicesSegmentsParams, callback: (error: any, response: any) => void): void; - segments(params: IndicesSegmentsParams): PromiseLike; + segments(params: IndicesSegmentsParams): Promise; shardStores(params: IndicesShardStoresParams, callback: (error: any, response: any) => void): void; - shardStores(params: IndicesShardStoresParams): PromiseLike; + shardStores(params: IndicesShardStoresParams): Promise; shrink(params: IndicesShrinkParams, callback: (error: any, response: any) => void): void; - shrink(params: IndicesShrinkParams): PromiseLike; + shrink(params: IndicesShrinkParams): Promise; stats(params: IndicesStatsParams, callback: (error: any, response: any) => void): void; - stats(params: IndicesStatsParams): PromiseLike; + stats(params: IndicesStatsParams): Promise; updateAliases(params: IndicesUpdateAliasesParams, callback: (error: any, response: any) => void): void; - updateAliases(params: IndicesUpdateAliasesParams): PromiseLike; + updateAliases(params: IndicesUpdateAliasesParams): Promise; upgrade(params: IndicesUpgradeParams, callback: (error: any, response: any) => void): void; - upgrade(params: IndicesUpgradeParams): PromiseLike; + upgrade(params: IndicesUpgradeParams): Promise; validateQuery(params: IndicesValidateQueryParams, callback: (error: any, response: any) => void): void; - validateQuery(params: IndicesValidateQueryParams): PromiseLike; + validateQuery(params: IndicesValidateQueryParams): Promise; } export interface IndicesAnalyzeParams extends GenericParams { @@ -1416,13 +1416,13 @@ declare module Elasticsearch { export class Ingest { deletePipeline(params: IngestDeletePipelineParams, callback: (error: any, response: any, status: any) => void): void; - deletePipeline(params: IngestDeletePipelineParams): PromiseLike; + deletePipeline(params: IngestDeletePipelineParams): Promise; getPipeline(params: IngestGetPipelineParams, callback: (error: any, response: any, status: any) => void): void; - getPipeline(params: IngestGetPipelineParams): PromiseLike; + getPipeline(params: IngestGetPipelineParams): Promise; putPipeline(params: IngestPutPipelineParams, callback: (error: any, response: any, status: any) => void): void; - putPipeline(params: IngestPutPipelineParams): PromiseLike; + putPipeline(params: IngestPutPipelineParams): Promise; simulate(params: IngestSimulateParams, callback: (error: any, response: any, status: any) => void): void; - simulate(params: IngestSimulateParams): PromiseLike; + simulate(params: IngestSimulateParams): Promise; } export interface IngestDeletePipelineParams extends GenericParams { @@ -1450,11 +1450,11 @@ declare module Elasticsearch { export class Nodes { hotThreads(params: NodesHotThreadsParams, callback: (error: any, response: any, status: any) => void): void; - hotThreads(params: NodesHotThreadsParams): PromiseLike; + hotThreads(params: NodesHotThreadsParams): Promise; info(params: NodesInfoParams, callback: (error: any, response: any, status: any) => void): void; - info(params: NodesInfoParams): PromiseLike; + info(params: NodesInfoParams): Promise; stats(params: NodesStatsParams, callback: (error: any, response: any, status: any) => void): void; - stats(params: NodesStatsParams): PromiseLike; + stats(params: NodesStatsParams): Promise; } export interface NodesHotThreadsParams extends GenericParams { @@ -1491,23 +1491,23 @@ declare module Elasticsearch { export class Snapshot { create(params: SnapshotCreateParams, callback: (error: any, response: any, status: any) => void): void; - create(params: SnapshotCreateParams): PromiseLike; + create(params: SnapshotCreateParams): Promise; createRepository(params: SnapshotCreateRepositoryParams, callback: (error: any, response: any, status: any) => void): void; - createRepository(params: SnapshotCreateRepositoryParams): PromiseLike; + createRepository(params: SnapshotCreateRepositoryParams): Promise; delete(params: SnapshotDeleteParams, callback: (error: any, response: any, status: any) => void): void; - delete(params: SnapshotDeleteParams): PromiseLike; + delete(params: SnapshotDeleteParams): Promise; deleteRepository(params: SnapshotDeleteRepositoryParams, callback: (error: any, response: any, status: any) => void): void; - deleteRepository(params: SnapshotDeleteRepositoryParams): PromiseLike; + deleteRepository(params: SnapshotDeleteRepositoryParams): Promise; get(params: SnapshotGetParams, callback: (error: any, response: any, status: any) => void): void; - get(params: SnapshotGetParams): PromiseLike; + get(params: SnapshotGetParams): Promise; getRepository(params: SnapshotGetRepositoryParams, callback: (error: any, response: any, status: any) => void): void; - getRepository(params: SnapshotGetRepositoryParams): PromiseLike; + getRepository(params: SnapshotGetRepositoryParams): Promise; restore(params: SnapshotRestoreParams, callback: (error: any, response: any, status: any) => void): void; - restore(params: SnapshotRestoreParams): PromiseLike; + restore(params: SnapshotRestoreParams): Promise; status(params: SnapshotStatusParams, callback: (error: any, response: any, status: any) => void): void; - status(params: SnapshotStatusParams): PromiseLike; + status(params: SnapshotStatusParams): Promise; verifyRepository(params: SnapshotVerifyRepositoryParams, callback: (error: any, response: any, status: any) => void): void; - verifyRepository(params: SnapshotVerifyRepositoryParams): PromiseLike; + verifyRepository(params: SnapshotVerifyRepositoryParams): Promise; } export interface SnapshotCreateParams extends GenericParams { @@ -1571,11 +1571,11 @@ declare module Elasticsearch { export class Tasks { cancel(params: TasksCancelParams, callback: (error: any, response: any, status: any) => void): void; - cancel(params: TasksCancelParams): PromiseLike; + cancel(params: TasksCancelParams): Promise; get(params: TasksGetParams, callback: (error: any, response: any, status: any) => void): void; - get(params: TasksGetParams): PromiseLike; + get(params: TasksGetParams): Promise; list(params: TasksListParams, callback: (error: any, response: any, status: any) => void): void; - list(params: TasksListParams): PromiseLike; + list(params: TasksListParams): Promise; } export interface TasksCancelParams extends GenericParams { diff --git a/types/google-map-react/google-map-react-tests.tsx b/types/google-map-react/google-map-react-tests.tsx index 959bb8e68a..c01d1e3cab 100644 --- a/types/google-map-react/google-map-react-tests.tsx +++ b/types/google-map-react/google-map-react-tests.tsx @@ -1,6 +1,9 @@ -import GoogleMapReact from 'google-map-react'; +import GoogleMapReact, { BootstrapURLKeys } from 'google-map-react'; import * as React from 'react'; const center = { lat: 0, lng: 0 }; -; +const key: BootstrapURLKeys = { key: 'my-google-maps-key' }; +const client: BootstrapURLKeys = { client: 'my-client-identifier', v: '3.28' , language: 'en' }; + +; diff --git a/types/google-map-react/index.d.ts b/types/google-map-react/index.d.ts index c1898a9e3f..5e54c4e5aa 100644 --- a/types/google-map-react/index.d.ts +++ b/types/google-map-react/index.d.ts @@ -6,10 +6,7 @@ import * as React from 'react'; -export interface BootstrapURLKeys { - key: string; - language?: string; -} +export type BootstrapURLKeys = ({ key: string; } | { client: string; v: string; }) & { language?: string }; export interface Options { styles?: any[]; diff --git a/types/hapi/index.d.ts b/types/hapi/index.d.ts index f0ed602864..91432e1d1f 100644 --- a/types/hapi/index.d.ts +++ b/types/hapi/index.d.ts @@ -1935,10 +1935,11 @@ export class Request extends Podium { /** same as pre but represented as the response object created by the pre method. */ preResponses: Object; /** - * an object containing the query parameters. - * TODO update with outcome of: https://github.com/hapijs/hapi/pull/3479 + * by default the object outputted from [node's URL parse()](https://nodejs.org/docs/latest/api/url.html#url_urlobject_query) method. + * Might also be set indirectly via [request.setUrl](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/17354#requestseturlurl-striptrailingslash) in which case it may be + * a string (if url is set to an object with the query attribute as an unparsed string). */ - query: Object; + query: any; /** an object containing the Node HTTP server objects. **Direct interaction with these raw objects is not recommended.** */ raw: { req: http.IncomingMessage; // Or http.ClientRequest http://www.apetuts.com/tutorial/node-js-http-client-request-class/ ? diff --git a/types/hapi/test/request/query.ts b/types/hapi/test/request/query.ts new file mode 100644 index 0000000000..c6507c2da0 --- /dev/null +++ b/types/hapi/test/request/query.ts @@ -0,0 +1,14 @@ +// Added test in addition to docs, for request.query + +import * as Hapi from 'hapi'; + +interface GetThingQuery { + name: string; +} + +const handler: Hapi.RouteHandler = function (request, reply) { + + const query = request.query as GetThingQuery; + + return reply(`You asked for ${query.name}`); +}; diff --git a/types/hapi/tsconfig.json b/types/hapi/tsconfig.json index 01c5a12c89..39ff8e810c 100644 --- a/types/hapi/tsconfig.json +++ b/types/hapi/tsconfig.json @@ -35,6 +35,7 @@ "test/request/generate-response.ts", "test/request/get-log.ts", "test/request/log.ts", + "test/request/query.ts", "test/request/set-method.ts", "test/request/set-url.ts", "test/request/tail.ts", diff --git a/types/heremaps/heremaps-tests.ts b/types/heremaps/heremaps-tests.ts index 01360c1bdf..d3e161cb74 100644 --- a/types/heremaps/heremaps-tests.ts +++ b/types/heremaps/heremaps-tests.ts @@ -44,7 +44,7 @@ let map = new H.Map(mapContainer, defaultLayers.normal.map, { // initial center and zoom level of the map zoom: 16, // Champs-Elysees - center: {lat: 48.869145, lng: 2.314298} + center: { lat: 48.869145, lng: 2.314298 } }); // Step 3: make the map interactive @@ -85,3 +85,78 @@ let polyline = new H.map.Polyline(new H.geo.Strip()); // tslint:disable-next-line:array-type let clipArr: Array>; clipArr = polyline.clip(new H.geo.Rect(5, 5, 5, 5)); + +let router = platform.getRoutingService(); +let calculateRouteParams = { + waypoint0: 'geo!52.5,13.4', + waypoint1: 'geo!52.5,13.45', + mode: 'fastest;car;traffic:disabled' +}; +router.calculateRoute( + calculateRouteParams, + (result) => { + console.log(result.response.route[0]); + }, + (error) => { + console.log(error); + } +); + +let places = platform.getPlacesService(); +let entryPoint = H.service.PlacesService.EntryPoint; +places.request( + entryPoint.SEARCH, + { + at: '52.5044,13.3909', + q: 'pizza' + }, + (response) => { + console.log(response); + let items = response.results.items; + places.follow( + items[0].href, + (resp) => { + console.log(resp); + }, + (resp) => { + console.log('ERROR: ' + resp); + } + ); + }, + (error) => { + console.log('ERROR: ' + error); + } +); + +let geocoder = platform.getGeocodingService(); +let geocodingParams: H.service.ServiceParameters = { + searchText: '425 W Randolph Street, Chicago' +}; +geocoder.geocode( + geocodingParams, + (result) => { + console.log(result); + console.log(result.Response.View[0].Result[0].Location.DisplayPosition); + }, + (error) => { + console.log(error); + } +); + +// deprecated but w/e +let enterprieseRouter = platform.getEnterpriseRoutingService(); +let calculateIsoline: H.service.ServiceParameters = { + start: 'geo!52.5,13.4', + distance: '1000,2000', + mode: 'fastest;car;traffic:disabled' +}; +enterprieseRouter.calculateIsoline( + calculateIsoline, + (result) => { + console.log(result); + console.log(result.Response.isolines[0]); + }, + (error) => { + console.log(error); + } +); diff --git a/types/heremaps/index.d.ts b/types/heremaps/index.d.ts index 206a932e68..ca32173bed 100644 --- a/types/heremaps/index.d.ts +++ b/types/heremaps/index.d.ts @@ -4301,14 +4301,15 @@ declare namespace H { /** * This is generic method to query places RestAPI. - * @param entryPoint {string} - can be one of available entry points H.service.PlacesService.EntryPoint i.e value of H.service.PlacesService.EntryPoint.SEARCH + * @param entryPoint {H.service.PlacesService.EntryPoint} - can be one of available entry points H.service.PlacesService.EntryPoint i.e value of H.service.PlacesService.EntryPoint.SEARCH * @param entryPointParams {Object} - parameter map key value pairs will be transformed into the url key=value parametes. For entry point parameters description please refer to places * restful api documentation documentation for available parameters for chose entry point * @param onResult {Function} - callback which is called when result is returned * @param onError {Function} - callback which is called when error occured (i.e request timeout) * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - request(entryPoint: string, entryPointParams: {}, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + request(entryPoint: H.service.PlacesService.EntryPoint, entryPointParams: {}, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): + H.service.JsonpRequestHandle; /** * Function triggers places api 'search' entry point. Please refer to documentation for parameter specification and response handling. @@ -4317,7 +4318,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - search(searchParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + search(searchParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * Function triggers places api 'suggestions' entry point. Please refer to documentation for parameter specification and response handling. @@ -4326,7 +4327,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - suggest(suggestParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + suggest(suggestParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * Function triggers places api 'explore' entry point. Please refer to documentation for parameter specification and response handling. @@ -4335,7 +4336,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - explore(exploreParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + explore(exploreParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * Function triggers places api 'around' entry point. Please refer to documentation for parameter specification and response handling. @@ -4344,7 +4345,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - around(aroundParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + around(aroundParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * Function triggers places api 'here' entry point. Please refer to documentation for parameter specification and response handling. @@ -4353,7 +4354,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - here(hereParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + here(hereParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * Function triggers places api 'categories' entry point. Please refer to documentation for parameter specification and response handling. @@ -4362,7 +4363,7 @@ declare namespace H { * @param onError {Function} * @returns {H.service.JsonpRequestHandle} - jsonp request handle */ - categories(categoriesParams: H.service.ServiceParameters, onResult: () => void, onError: () => void): H.service.JsonpRequestHandle; + categories(categoriesParams: H.service.ServiceParameters, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * This method should be used to follow hyperlinks available in results returned by dicovery queries. @@ -4372,7 +4373,7 @@ declare namespace H { * @param opt_additionalParameters {Object=} - additional parameters to send with request * @returns {H.service.JsonpRequestHandle} - jsonp resquest handle */ - follow(hyperlink: string, onResult: () => void, onError: () => void, opt_additionalParameters?: {}): H.service.JsonpRequestHandle; + follow(hyperlink: string, onResult: (result: H.service.ServiceResult) => void, onError: (error: Error) => void, opt_additionalParameters?: {}): H.service.JsonpRequestHandle; } namespace PlacesService { @@ -4605,7 +4606,140 @@ declare namespace H { * This type encapsulates a response object provider by a HERE platform service. */ interface ServiceResult { - [key: string]: string; + [key: string]: any; + response?: { + language?: string, + route?: Array<{ + leg: Array<{ + maneuver: Array<{ + id: string, + instruction: string, + length: number, + note: string[], + position: { + latitude: number, + longitude: number + }, + shape: string[], + travelTime: number, + _type: string + }> + }>, + mode: { + feature: any[], + trafficMode: string, + transportModes: string[], + type: string + } + shape: string[], + summary: { + baseTime: number, + distance: number, + flags: string[], + text: string, + trafficTime: number, + travelTime: number + } + waypoint: Array<{ + label: string, + linkId: string, + mappedPosition: { + latitude: number, + longitude: number + }, + mappedRoadName: string, + originalPosition: { + latitude: number, + longitude: number + }, + shapeIndex: number, + sideOfStreet: string, + spot: number, + type: string + }> + }>, + metaInfo: {} + }; + results?: { + items?: any[], + next?: string + }; + search?: { + context: { + href: string, + location: { + address: { + city: string, + country: string, + countryCode: string, + county: string, + district: string, + house: string, + postalCode: string, + stateCode: string, + street: string, + text: string + }, + position: number[] + }, + type: string + } + }; + Response?: { + MetaInfo: { + Timestamp: string + }, + View: Array<{ + Result: Array<{ + Location: { + Address: { + AdditionalData: Array<{ + key: string, + value: string + }>, + City: string, + Country: string, + County: string, + District: string, + HouseNumber: string, + Label: string, + PostalCode: string, + State: string, + Street: string + }, + DisplayPosition: { + Latitude: number, + Longitude: number + }, + LocationId: string, + LocationType: string, + MapView: { + BottomRight: { + Latitude: number, + Longitude: number + }, + TopLeft: { + Latitude: number, + Longitude: number + } + }, + NavigationPosition: Array<{ + Latitude: number, + Longitude: number + }> + }, + MatchLevel: string, + MatchQuality: { + City: number, + HouseNumber: number, + Street: number[] + }, + MatchType: string, + Relevance: number + }> + }>, + isolines: any[] + }; } /** @@ -4634,7 +4768,7 @@ declare namespace H { * @param onError {function()} * @returns {H.service.JsonpRequestHandle} */ - requestIncidents(serviceParams: H.service.ServiceParameters, onResponse: (result: H.service.ServiceResult) => void, onError: () => void): H.service.JsonpRequestHandle; + requestIncidents(serviceParams: H.service.ServiceParameters, onResponse: (result: H.service.ServiceResult) => void, onError: (error: Error) => void): H.service.JsonpRequestHandle; /** * This method requests traffic incident information by tile coordinates @@ -4646,8 +4780,8 @@ declare namespace H { * @param opt_serviceParams {H.service.ServiceParameters=} - optional service parameters to be added to the request * @returns {H.service.JsonpRequestHandle} */ - requestIncidentsByTile(x: number, y: number, z: number, onResponse: (result: H.service.ServiceResult) => void, onError: () => void, opt_serviceParams?: H.service.ServiceParameters): - H.service.JsonpRequestHandle; + requestIncidentsByTile(x: number, y: number, z: number, onResponse: (result: H.service.ServiceResult) => void, onError: (error: Error) => void, + opt_serviceParams?: H.service.ServiceParameters): H.service.JsonpRequestHandle; } namespace TrafficIncidentsService { diff --git a/types/jake/index.d.ts b/types/jake/index.d.ts index cb23f992f0..98fc72d148 100644 --- a/types/jake/index.d.ts +++ b/types/jake/index.d.ts @@ -38,7 +38,7 @@ declare function fail(...err:any[]): void; * @param action The action to perform for this task * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task. */ -declare function file(name:string, prereqs?:string[], action?:()=>void, opts?:jake.FileTaskOptions): jake.FileTask; +declare function file(name:string, prereqs?:string[], action?:(this: jake.FileTask)=>void, opts?:jake.FileTaskOptions): jake.FileTask; /** * Creates Jake FileTask from regex patterns @@ -63,9 +63,9 @@ declare function namespace(name:string, scope:()=>void): void; * @param action The action to perform for this task * @param opts */ -declare function task(name:string, prereqs?:string[], action?:(...params:any[])=>any, opts?:jake.TaskOptions): jake.Task; -declare function task(name:string, action?:(...params:any[])=>any, opts?:jake.TaskOptions): jake.Task; -declare function task(name:string, opts?:jake.TaskOptions, action?:(...params:any[])=>any): jake.Task; +declare function task(name:string, prereqs?:string[], action?:(this: jake.Task, ...params:any[])=>any, opts?:jake.TaskOptions): jake.Task; +declare function task(name:string, action?:(this: jake.Task, ...params:any[])=>any, opts?:jake.TaskOptions): jake.Task; +declare function task(name:string, opts?:jake.TaskOptions, action?:(this: jake.Task, ...params:any[])=>any): jake.Task; /** * @param name The name of the NpmPublishTask @@ -214,7 +214,7 @@ declare namespace jake{ * @param action The action to perform for this task * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task. */ - constructor(name:string, prereqs?:string[], action?:()=>void, opts?:TaskOptions); + constructor(name:string, prereqs?:string[], action?:(this: Task)=>void, opts?:TaskOptions); /** * Runs prerequisites, then this task. If the task has already been run, will not run the task again. @@ -236,10 +236,19 @@ declare namespace jake{ listeners(event: string): Function[]; emit(event: string, ...args: any[]): boolean; listenerCount(type: string): number; + complete(value?: any): void; value: any; + + name?: string; + prereqs?: string[]; + action?: (...params: any[]) => any; + taskStatus?: string; + async?: boolean; + description?: string; + fullName: string; } - export class DirectoryTask{ + export class DirectoryTask extends FileTask { /** * @param name The name of the directory to create. */ @@ -254,14 +263,14 @@ declare namespace jake{ async?: boolean; } - export class FileTask{ + export class FileTask extends Task{ /** * @param name The name of the Task * @param prereqs Prerequisites to be run before this task * @param action The action to perform to create this file * @param opts Perform this task asynchronously. If you flag a task with this option, you must call the global `complete` method inside the task's action, for execution to proceed to the next task. */ - constructor(name:string, prereqs?:string[], action?:()=>void, opts?:FileTaskOptions); + constructor(name:string, prereqs?:string[], action?:(this: FileTask)=>void, opts?:FileTaskOptions); } interface FileFilter{ diff --git a/types/jasmine-ajax/index.d.ts b/types/jasmine-ajax/index.d.ts index dcc6720f04..0d1d92751d 100644 --- a/types/jasmine-ajax/index.d.ts +++ b/types/jasmine-ajax/index.d.ts @@ -24,6 +24,8 @@ interface JasmineAjaxRequest extends XMLHttpRequest { data(): string; respondWith(response: JasmineAjaxResponse): void; + responseTimeout(): void; + responseError(): void; } interface JasmineAjaxRequestTracker { diff --git a/types/jquery-mousewheel/index.d.ts b/types/jquery-mousewheel/index.d.ts index fdeaa39585..d89bbb9942 100644 --- a/types/jquery-mousewheel/index.d.ts +++ b/types/jquery-mousewheel/index.d.ts @@ -17,6 +17,7 @@ declare namespace JQueryMousewheel { } interface JQuery { + on(event: 'mousewheel', handler: (eventObject: JQueryMousewheel.JQueryMousewheelEventObject, ...args: any[]) => any): JQuery; mousewheel(handler: (eventObject: JQueryMousewheel.JQueryMousewheelEventObject, ...args: any[]) => any): JQuery unmousewheel(): JQuery; } diff --git a/types/jquery.pjax/index.d.ts b/types/jquery.pjax/index.d.ts index ebb713236e..e71dec35e4 100644 --- a/types/jquery.pjax/index.d.ts +++ b/types/jquery.pjax/index.d.ts @@ -9,14 +9,14 @@ /** * Interface for pjax:popstate event. */ -interface PjaxPopStateEventObject extends JQueryEventObject { +interface PjaxPopStateEventObject extends JQuery.Event { /** * Navigation direction. Could be "back" or "forward". */ direction: string } -interface PjaxSettings extends JQueryAjaxSettings { +interface PjaxSettings extends JQuery.AjaxSettings { /** * A jQuery selector indicates where to stick the response body. E.g., $(container).html(xhr.responseBody). * If it is not defined, the `data-pjax` attribute of the link will be treated as container. @@ -33,7 +33,7 @@ interface PjaxSettings extends JQueryAjaxSettings { * Whether to replaceState the URL. Defaults to false. */ replace?: boolean; - + /** * How many requests to cache. Defaults to 20. */ @@ -90,6 +90,8 @@ interface JQuery { * @return Returns the jQuery object */ pjax(delegationSelector: string, containerSelector?: string, options?: PjaxSettings): JQuery; + + on(event: 'pjax:popstate', handler: (e: PjaxPopStateEventObject) => void): this; } interface JQueryStatic { @@ -120,7 +122,7 @@ interface PjaxStatic { * - push: a boolean indicates whether to pushState the URL. Default is true. * - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false. */ - click(event: JQueryEventObject, options?: PjaxSettings): void; + click(event: JQuery.Event, options?: PjaxSettings): void; /** * PJAX on click handler. @@ -131,7 +133,7 @@ interface PjaxStatic { * - push: a boolean indicates whether to pushState the URL. Default is true. * - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false. */ - click(event: JQueryEventObject, containerSelector?: string, options?: PjaxSettings): void; + click(event: JQuery.Event, containerSelector?: string, options?: PjaxSettings): void; /** * PJAX on form submit handler @@ -141,7 +143,7 @@ interface PjaxStatic { * - push: a boolean indicates whether to pushState the URL. Default is true. * - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false. */ - submit(event: JQueryEventObject, options?: PjaxSettings): void; + submit(event: JQuery.Event, options?: PjaxSettings): void; /** * PJAX on form submit handler @@ -152,7 +154,7 @@ interface PjaxStatic { * - push: a boolean indicates whether to pushState the URL. Default is true. * - replace: a boolean indicates whether to use replaceState instead of pushState. Default is false. */ - submit(event: JQueryEventObject, containerSelector?: string, options?: PjaxSettings): void; + submit(event: JQuery.Event, containerSelector?: string, options?: PjaxSettings): void; /** * Install pjax functions on $.pjax to enable pushState behavior. Does nothing if already enabled. diff --git a/types/jquery.pjax/jquery.pjax-tests.ts b/types/jquery.pjax/jquery.pjax-tests.ts index 91cc9391a2..04c9ee5ab3 100644 --- a/types/jquery.pjax/jquery.pjax-tests.ts +++ b/types/jquery.pjax/jquery.pjax-tests.ts @@ -61,9 +61,9 @@ function test_support() { } function test_events() { - $(document).on('pjax:popstate', function(e: PjaxPopStateEventObject) { + $(document).on('pjax:popstate', function(e) { if (e.direction === 'back') { console.log('pjax:popstate is OK'); } }); -} \ No newline at end of file +} diff --git a/types/jquery.pjax/tsconfig.json b/types/jquery.pjax/tsconfig.json index e48007101b..5364759f80 100644 --- a/types/jquery.pjax/tsconfig.json +++ b/types/jquery.pjax/tsconfig.json @@ -20,4 +20,4 @@ "index.d.ts", "jquery.pjax-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/jquery/README.md b/types/jquery/README.md index d1bbad05fc..8fab451ce0 100644 --- a/types/jquery/README.md +++ b/types/jquery/README.md @@ -9,7 +9,7 @@ When jQuery is globally available, you can use `jQuery` and `$` directly. When you want to import jQuery as a module and have a global DOM available (e.g. browser and browser-like environments): ```typescript -import * as jQuery from 'jquery'; +import jQuery = require('jquery'); ``` #### Importing (without a global DOM available) @@ -23,6 +23,21 @@ const jQuery = jQueryFactory(window, true); Note that while the factory function ignores the second parameter, it is required to get correct type declarations. +### Project structure + +- [jquery-tests.ts](jquery-tests.ts) + - Tests that exercise TypeScript-specific usage and cases not covered by other test files. +- [test/example-tests.ts](test/example-tests.ts) + - Tests generated from examples in jQuery documentation. +- [test/longdesc-tests.ts](test/longdesc-tests.ts) + - Tests generated from non-example snippets in jQuery documentation. +- [test/jquery-window-module-tests.ts](test/jquery-window-module-tests.ts)
+ [test/jquery-slim-window-module-tests.ts](test/jquery-slim-window-module-tests.ts) + - Tests importing jQuery with a DOM available +- [test/jquery-no-window-module-tests.ts](test/jquery-no-window-module-tests.ts)
+ [test/jquery-slim-no-window-module-tests.ts](test/jquery-slim-no-window-module-tests.ts) + - Tests importing jQuery without a DOM available + ### Authoring type definitions for jQuery plugins `$.fn` is represented by `JQuery`. diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 2c7d5ce75a..ac047d0167 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -62,7 +62,7 @@ interface JQuery { * @see {@link https://api.jquery.com/add/} * @since 1.4 */ - add(selector: JQuery.Selector, context: Element): JQuery; + add(selector: JQuery.Selector, context: Element): this; /** * Create a new jQuery object with elements added to the set of matched elements. * @@ -74,7 +74,7 @@ interface JQuery { * @since 1.0 * @since 1.3.2 */ - add(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery.htmlString | JQuery): JQuery; + add(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery.htmlString | JQuery): this; /** * Add the previous set of elements on the stack to the current set, optionally filtered by a selector. * @@ -103,7 +103,7 @@ interface JQuery { * @see {@link https://api.jquery.com/after/} * @since 1.0 */ - after(...contents: Array | JQuery>): this; + after(...contents: Array | JQuery>): this; /** * Insert content, specified by the parameter, after each element in the set of matched elements. * @@ -115,7 +115,7 @@ interface JQuery { * @since 1.4 * @since 1.10 */ - after(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; + after(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; /** * Register a handler to be called when Ajax requests complete. This is an AjaxEvent. * @@ -219,7 +219,7 @@ interface JQuery { * @see {@link https://api.jquery.com/append/} * @since 1.0 */ - append(...contents: Array | JQuery>): this; + append(...contents: Array | JQuery>): this; /** * Insert content, specified by the parameter, to the end of each element in the set of matched elements. * @@ -230,7 +230,7 @@ interface JQuery { * @see {@link https://api.jquery.com/append/} * @since 1.4 */ - append(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; + append(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; /** * Insert every element in the set of matched elements to the end of the target. * @@ -277,7 +277,7 @@ interface JQuery { * @see {@link https://api.jquery.com/before/} * @since 1.0 */ - before(...contents: Array | JQuery>): this; + before(...contents: Array | JQuery>): this; /** * Insert content, specified by the parameter, before each element in the set of matched elements. * @@ -289,7 +289,7 @@ interface JQuery { * @since 1.4 * @since 1.10 */ - before(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; + before(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; // [bind() overloads] https://github.com/jquery/api.jquery.com/issues/1048 /** * Attach a handler to an event for the elements. @@ -426,14 +426,14 @@ interface JQuery { * @since 1.3 * @since 1.6 */ - closest(selector: JQuery.Selector | JQuery | Element): this; + closest(selector: JQuery.Selector | Element | JQuery): this; /** * Get the children of each element in the set of matched elements, including text and comment nodes. * * @see {@link https://api.jquery.com/contents/} * @since 1.2 */ - contents(): this; + contents(): JQuery; /** * Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. * @@ -620,7 +620,7 @@ interface JQuery { * @see {@link https://api.jquery.com/each/} * @since 1.0 */ - each(fn: (this: TElement, index: number, element: Element) => void | false): this; + each(fn: (this: TElement, index: number, element: TElement) => void | false): this; /** * Remove all child nodes of the set of matched elements from the DOM. * @@ -653,7 +653,7 @@ interface JQuery { * @see {@link https://api.jquery.com/jQuery.fn.extend/} * @since 1.0 */ - extend(obj: object): JQuery; + extend(obj: object): this; /** * Display the matched elements by fading them to opaque. * @@ -796,7 +796,7 @@ interface JQuery { * @since 1.0 * @since 1.6 */ - find(selector: JQuery.Selector | Element | JQuery): JQuery; + find(selector: JQuery.Selector | Element | JQuery): this; /** * Stop the currently-running animation, remove all queued animations, and complete all animations for * the matched elements. @@ -985,7 +985,7 @@ interface JQuery { * @since 1.0 * @since 1.4 */ - index(element?: Element | JQuery | JQuery.Selector): number; + index(element?: JQuery.Selector | Element | JQuery): number; /** * Set the CSS inner height of each element in the set of matched elements. * @@ -1058,7 +1058,7 @@ interface JQuery { * @since 1.0 * @since 1.6 */ - is(selector: JQuery.Selector | ((this: TElement, index: number, element: TElement) => boolean) | JQuery | Element | Element[]): boolean; + is(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery | ((this: TElement, index: number, element: TElement) => boolean)): boolean; /** * Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. * @@ -1148,7 +1148,7 @@ interface JQuery { * @see {@link https://api.jquery.com/map/} * @since 1.2 */ - map(callback: (this: TElement, index: number, domElement: TElement) => any | any[] | null | undefined): JQuery; + map(callback: (this: TElement, index: number, domElement: TElement) => any | any[] | null | undefined): this; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @@ -1309,7 +1309,7 @@ interface JQuery { * @since 1.0 * @since 1.4 */ - not(selector: JQuery.Selector | JQuery.TypeOrArray | ((this: TElement, index: number, element: TElement) => boolean) | JQuery): this; + not(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery | ((this: TElement, index: number, element: TElement) => boolean)): this; /** * Remove an event handler. * @@ -1629,7 +1629,7 @@ interface JQuery { * @see {@link https://api.jquery.com/prepend/} * @since 1.0 */ - prepend(...contents: Array | JQuery>): this; + prepend(...contents: Array | JQuery>): this; /** * Insert content, specified by the parameter, to the beginning of each element in the set of matched elements. * @@ -1640,7 +1640,7 @@ interface JQuery { * @see {@link https://api.jquery.com/prepend/} * @since 1.4 */ - prepend(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; + prepend(fn: (this: TElement, index: number, html: string) => JQuery.htmlString | JQuery.TypeOrArray | JQuery): this; /** * Insert every element in the set of matched elements to the beginning of the target. * @@ -1688,7 +1688,7 @@ interface JQuery { * @see {@link https://api.jquery.com/promise/} * @since 1.6 */ - promise(type: string, target: T): T & JQuery.Promise; + promise(type: string, target: T): T & JQuery.Promise; /** * Return a Promise object to observe when all actions of a certain type bound to the collection, * queued or not, have finished. @@ -1697,7 +1697,7 @@ interface JQuery { * @see {@link https://api.jquery.com/promise/} * @since 1.6 */ - promise(target: T): T & JQuery.Promise; + promise(target: T): T & JQuery.Promise; /** * Return a Promise object to observe when all actions of a certain type bound to the collection, * queued or not, have finished. @@ -1751,7 +1751,7 @@ interface JQuery { * @see {@link https://api.jquery.com/pushStack/} * @since 1.3 */ - pushStack(elements: ArrayLike, name: string, args: any[]): JQuery; + pushStack(elements: ArrayLike, name: string, args: any[]): this; /** * Add a collection of DOM elements onto the jQuery stack. * @@ -1759,7 +1759,7 @@ interface JQuery { * @see {@link https://api.jquery.com/pushStack/} * @since 1.0 */ - pushStack(elements: ArrayLike): JQuery; + pushStack(elements: ArrayLike): this; /** * Manipulate the queue of functions to be executed, once for each matched element. * @@ -1858,7 +1858,7 @@ interface JQuery { * @since 1.2 * @since 1.4 */ - replaceWith(newContent: JQuery.htmlString | JQuery.TypeOrArray | JQuery | ((this: TElement) => any)): JQuery; + replaceWith(newContent: JQuery.htmlString | JQuery | JQuery.TypeOrArray | ((this: TElement) => any)): this; /** * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @@ -2329,7 +2329,7 @@ interface JQuery { * @see {@link https://api.jquery.com/val/} * @since 1.0 */ - val(): string | number | string[] | undefined; + val(): string | number | string[] | null | undefined; /** * Set the CSS width of each element in the set of matched elements. * @@ -2388,7 +2388,7 @@ interface JQuery { * @since 1.2 * @since 1.4 */ - wrapInner(wrappingElement: JQuery.Selector | JQuery.htmlString | Element | JQuery | ((this: TElement, index: number) => string | Element | JQuery)): this; + wrapInner(wrappingElement: JQuery.Selector | JQuery.htmlString | Element | JQuery | ((this: TElement, index: number) => string | JQuery | Element)): this; } interface JQuery extends ArrayLike, Iterable { } @@ -2411,7 +2411,7 @@ interface JQueryStatic { * @since 1.4.3 */ cssNumber: JQuery.PlainObject; - readonly fn: JQuery; + readonly fn: JQuery; fx: { /** * The rate (in milliseconds) at which animations fire. @@ -2436,7 +2436,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.ready/} * @since 1.8 */ - ready: JQuery.Thenable; + ready: JQuery.Thenable>; /** * A collection of properties that represent the presence of different browser features or bugs. * Intended for jQuery's internal use; specific properties may be removed when they are no longer @@ -2489,7 +2489,9 @@ interface JQueryStatic { * @since 1.0 * @since 1.4 */ - (selector_object_callback?: JQuery.Selector | JQuery.TypeOrArray | JQuery.PlainObject | JQuery | (($: JQueryStatic) => void)): JQuery; + (selector_object_callback?: JQuery.Selector | JQuery.htmlString | JQuery.TypeOrArray | JQuery | + JQuery.PlainObject | + ((this: Document, $: JQueryStatic) => void)): JQuery; /** * A multi-purpose callbacks list object that provides a powerful way to manage callback lists. * @@ -2629,7 +2631,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.each/} * @since 1.0 */ - each(array: ArrayLike, callback: (indexInArray: number, value: T) => false | any): ArrayLike; + each(array: ArrayLike, callback: (this: T, indexInArray: number, value: T) => false | any): ArrayLike; /** * A generic iterator function, which can be used to seamlessly iterate over both objects and arrays. * Arrays and array-like objects with a length property (such as a function's arguments object) are @@ -2640,7 +2642,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.each/} * @since 1.0 */ - each(obj: T, callback: (propertyName: K, valueOfProperty: T[K]) => false | any): T; + each(obj: T, callback: (this: T[K], propertyName: K, valueOfProperty: T[K]) => false | any): T; /** * Takes a string and throws an exception containing it. * @@ -2648,7 +2650,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.error/} * @since 1.4.1 */ - error(message: string): never; + error(message: string): any; /** * Escapes any character that has a special meaning in a CSS selector. * @@ -2719,7 +2721,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.extend/} * @since 1.1.4 */ - extend(deep: true, target: T, ...objects: U[]): T & U; + extend(deep: true, target: any, object1: any, ...objects: any[]): any; /** * Merge the contents of two or more objects together into the first object. * @@ -2782,7 +2784,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.extend/} * @since 1.0 */ - extend(target: T, ...objects: U[]): T & U; + extend(target: any, object1: any, ...objects: any[]): any; /** * Load data from the server using a HTTP GET request. * @@ -2835,7 +2837,7 @@ interface JQueryStatic { * @since 1.12 * @since 2.2 */ - get(url_settings?: string | JQuery.AjaxSettings): JQuery.jqXHR; + get(url_settings?: string | JQuery.UrlAjaxSettings): JQuery.jqXHR; /** * Load JSON-encoded data from the server using a GET HTTP request. * @@ -2868,7 +2870,7 @@ interface JQueryStatic { * @since 1.0 */ getScript(url: string, - success?: JQuery.jqXHR.DoneCallback): JQuery.jqXHR; + success?: JQuery.jqXHR.DoneCallback): JQuery.jqXHR; /** * Execute some JavaScript code globally. * @@ -2915,7 +2917,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.htmlPrefilter/} * @since 1.12/2.2 */ - htmlPrefilter(html: string): string; + htmlPrefilter(html: JQuery.htmlString): JQuery.htmlString; /** * Search for a specified value within an array and return its index (or -1 if not found). * @@ -3029,7 +3031,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.noConflict/} * @since 1.0 */ - noConflict(removeAll?: boolean): JQueryStatic; + noConflict(removeAll?: boolean): this; /** * An empty function. * @@ -3065,7 +3067,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.parseHTML/} * @since 1.8 */ - parseHTML(data: string, context: Document | null | undefined, keepScripts: boolean): Node[]; + parseHTML(data: string, context: Document | null | undefined, keepScripts: boolean): JQuery.Node[]; /** * Parses a string into an array of DOM nodes. * @@ -3075,7 +3077,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.parseHTML/} * @since 1.8 */ - parseHTML(data: string, context_keepScripts?: Document | null | undefined | boolean): Node[]; + parseHTML(data: string, context_keepScripts?: Document | null | undefined | boolean): JQuery.Node[]; /** * Takes a well-formed JSON string and returns the resulting JavaScript value. * @@ -3145,7 +3147,7 @@ interface JQueryStatic { * @since 1.12 * @since 2.2 */ - post(url_settings?: string | JQuery.AjaxSettings): JQuery.jqXHR; + post(url_settings?: string | JQuery.UrlAjaxSettings): JQuery.jqXHR; /** * Takes a function and returns a new one that will always have a particular context. * @@ -3178,16 +3180,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.queue/} * @since 1.3 */ - queue(element: Element, queueName: string, newQueue: JQuery.TypeOrArray>): JQuery; - /** - * Show the queue of functions to be executed on the matched element. - * - * @param element A DOM element to inspect for an attached queue. - * @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue. - * @see {@link https://api.jquery.com/jQuery.queue/} - * @since 1.3 - */ - queue(element: Element, queueName?: string): JQuery.Queue; + queue(element: T, queueName?: string, newQueue?: JQuery.TypeOrArray>): JQuery.Queue; /** * Handles errors thrown synchronously in functions wrapped in jQuery(). * @@ -3204,7 +3197,7 @@ interface JQueryStatic { * @see {@link https://api.jquery.com/jQuery.removeData/} * @since 1.2.3 */ - removeData(element: Element, name?: string): JQuery; + removeData(element: Element, name?: string): void; /** * Creates an object containing a set of properties ready to be used in the definition of custom animations. * @@ -3215,38 +3208,28 @@ interface JQueryStatic { * @since 1.1 */ speed(duration: JQuery.Duration, easing: string, complete: (this: TElement) => void): JQuery.EffectsOptions; - /** - * Creates an object containing a set of properties ready to be used in the definition of custom animations. - * - * @param easing A string indicating which easing function to use for the transition. - * @param complete A function to call once the animation is complete, called once per matched element. - * @see {@link https://api.jquery.com/jQuery.speed/} - * @since 1.1 - */ - speed(easing: string, complete: (this: TElement) => void): JQuery.EffectsOptions; /** * Creates an object containing a set of properties ready to be used in the definition of custom animations. * * @param duration A string or number determining how long the animation will run. - * @param easing_complete_settings A string indicating which easing function to use for the transition. - * A function to call once the animation is complete, called once per matched element. + * @param easing_complete A string indicating which easing function to use for the transition. + * A function to call once the animation is complete, called once per matched element. * @see {@link https://api.jquery.com/jQuery.speed/} * @since 1.0 * @since 1.1 */ speed(duration: JQuery.Duration, - easing_complete_settings: string | ((this: TElement) => void) | JQuery.SpeedSettings): JQuery.EffectsOptions; + easing_complete: string | ((this: TElement) => void)): JQuery.EffectsOptions; /** * Creates an object containing a set of properties ready to be used in the definition of custom animations. * - * @param duration_easing_complete_settings A string or number determining how long the animation will run. - * A string indicating which easing function to use for the transition. - * A function to call once the animation is complete, called once per matched element. + * @param duration_complete_settings A string or number determining how long the animation will run. + * A function to call once the animation is complete, called once per matched element. * @see {@link https://api.jquery.com/jQuery.speed/} * @since 1.0 * @since 1.1 */ - speed(duration_easing_complete_settings?: JQuery.Duration | string | ((this: TElement) => void) | JQuery.SpeedSettings): JQuery.EffectsOptions; + speed(duration_complete_settings?: JQuery.Duration | ((this: TElement) => void) | JQuery.SpeedSettings): JQuery.EffectsOptions; /** * Remove the whitespace from the beginning and end of a string. * @@ -3298,6 +3281,7 @@ interface JQueryStatic { declare namespace JQuery { type TypeOrArray = T | T[]; + type Node = Element | Text | Comment; /** * A string is designated htmlString in jQuery documentation when it is used to represent one or more @@ -3325,262 +3309,18 @@ declare namespace JQuery { // region Ajax - /** - * @see {@link http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings} - */ - interface AjaxSettings { - /** - * A set of key/value pairs that map a given dataType to its MIME type, which gets sent in the Accept - * request header. This header tells the server what kind of response it will accept in return. - */ - accepts?: PlainObject; - /** - * By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need - * synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests - * do not support synchronous operation. Note that synchronous requests may temporarily lock the - * browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: - * false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback - * options instead of the corresponding methods of the jqXHR object such as jqXHR.done(). - */ - async?: boolean; - /** - * A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, - * XMLHTTPRequest) object before it is sent. Use this to set custom headers, etc. The jqXHR and - * settings objects are passed as arguments. This is an Ajax Event. Returning false in the beforeSend - * function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless - * of the type of request. - */ - beforeSend?(this: TContext, jqXHR: jqXHR, settings: AjaxSettings): false | void; - /** - * If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache - * to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" - * to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a - * POST is made to a URL that has already been requested by a GET. - */ - cache?: boolean; - /** - * A function to be called when the request finishes (after success and error callbacks are executed). - * The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a - * string categorizing the status of the request ("success", "notmodified", "nocontent", "error", - * "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of - * functions. Each function will be called in turn. This is an Ajax Event. - */ - complete?: TypeOrArray>; - /** - * An object of string/regular-expression pairs that determine how jQuery will parse the response, - * given its content type. - */ - contents?: PlainObject; - /** - * When sending data to the server, use this content type. Default is - * "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly - * pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). - * As of jQuery 1.6 you can pass false to tell jQuery to not set any content type header. Note: The W3C - * XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset - * will not force the browser to change the encoding. Note: For cross-domain requests, setting the - * content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or - * text/plain will trigger the browser to send a preflight OPTIONS request to the server. - */ - contentType?: string | false; - /** - * This object will be the context of all Ajax-related callbacks. By default, the context is an object - * that represents the Ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). - */ - context?: TContext; - /** - * An object containing dataType-to-dataType converters. Each converter's value is a function that - * returns the transformed value of the response. - */ - converters?: PlainObject<((value: any) => any) | true>; - /** - * If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of - * crossDomain to true. This allows, for example, server-side redirection to another domain. - */ - crossDomain?: boolean; - /** - * Data to be sent to the server. It is converted to a query string, if not already a string. It's - * appended to the url for GET-requests. See processData option to prevent this automatic processing. - * Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same - * key based on the value of the traditional setting (described below). - */ - data?: PlainObject | string | any[]; - /** - * A function to be used to handle the raw response data of XMLHttpRequest. This is a pre-filtering - * function to sanitize the response. You should return the sanitized data. The function accepts two - * arguments: The raw data returned from the server and the 'dataType' parameter. - */ - dataFilter?(data: string, type: string): any; - /** - * The type of data that you're expecting back from the server. If none is specified, jQuery will try - * to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON - * will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be - * returned as a string). The available types (and the result passed as the first argument to your - * success callback) are: - * - * "xml": Returns a XML document that can be processed via jQuery. - * - * "html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM. - * - * "script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by - * appending a query string parameter, _=[TIMESTAMP], to the URL unless the cache option is set to - * true. Note: This will turn POSTs into GETs for remote-domain requests. - * - * "json": Evaluates the response as JSON and returns a JavaScript object. Cross-domain "json" requests - * are converted to "jsonp" unless the request includes jsonp: false in its request options. The JSON - * data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of - * jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} - * instead. (See json.org for more information on proper JSON formatting.) - * - * "jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to - * specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to - * the URL unless the cache option is set to true. - * - * "text": A plain text string. - * - * multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it - * received in the Content-Type header to what you require. For example, if you want a text response to - * be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it - * received as text, and interpreted by jQuery as XML: "jsonp text xml". Similarly, a shorthand string - * such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from - * jsonp to text, and then from text to xml. - */ - dataType?: 'xml' | 'html' | 'script' | 'json' | 'jsonp' | 'text' | string; - /** - * A function to be called if the request fails. The function receives three arguments: The jqXHR (in - * jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an - * optional exception object, if one occurred. Possible values for the second argument (besides null) - * are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives - * the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery - * 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: - * This handler is not called for cross-domain script and cross-domain JSONP requests. This is an Ajax Event. - */ - error?: TypeOrArray>; - /** - * Whether to trigger global Ajax event handlers for this request. The default is true. Set to false to - * prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to - * control various Ajax Events. - */ - global?: boolean; - /** - * An object of additional header key/value pairs to send along with requests using the XMLHttpRequest - * transport. The header X-Requested-With: XMLHttpRequest is always added, but its default - * XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from - * within the beforeSend function. - */ - 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 - * 1.4 this technique also checks the 'etag' specified by the server to catch unmodified data. - */ - ifModified?: boolean; - /** - * Allow the current environment to be recognized as "local," (e.g. the filesystem), even if jQuery - * does not recognize it as such by default. The following protocols are currently recognized as local: - * file, *-extension, and widget. If the isLocal setting needs modification, it is recommended to do so - * once in the $.ajaxSetup() method. - */ - isLocal?: boolean; - /** - * Override the callback function name in a JSONP request. This value will be used instead of - * 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would - * result in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the jsonp option to false - * prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for - * transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, - * { jsonp: false, jsonpCallback: "callbackName" }. If you don't trust the target of your Ajax - * requests, consider setting the jsonp property to false for security reasons. - */ - jsonp?: string | boolean; - /** - * Specify the callback function name for a JSONP request. This value will be used instead of the - * random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name - * as it'll make it easier to manage the requests and provide callbacks and error handling. You may - * want to specify the callback when you want to enable better browser caching of GET requests. As of - * jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback - * is set to the return value of that function. - */ - jsonpCallback?: string | ((this: TContext) => string); - /** - * The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). - */ - method?: string; - /** - * A mime type to override the XHR mime type. - */ - mimeType?: string; - /** - * A password to be used with XMLHttpRequest in response to an HTTP access authentication request. - */ - password?: string; - /** - * By default, data passed in to the data option as an object (technically, anything other than a - * string) will be processed and transformed into a query string, fitting to the default content-type - * "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, - * set this option to false. - */ - processData?: boolean; - /** - * Only applies when the "script" transport is used (e.g., cross-domain requests with "jsonp" or - * "script" dataType and "GET" type). Sets the charset attribute on the script tag used in the request. - * Used when the character set on the local page is not the same as the one on the remote script. - */ - scriptCharset?: string; - /** - * An object of numeric HTTP codes and functions to be called when the response has the corresponding - * code. - * - * If the request is successful, the status code functions take the same parameters as the success - * callback; if it results in an error (including 3xx redirect), they take the same parameters as the error callback. - */ - statusCode?: PlainObject | Ajax.ErrorCallback>; - /** - * A function to be called if the request succeeds. The function gets passed three arguments: The data - * returned from the server, formatted according to the dataType parameter or the dataFilter callback - * function, if specified; a string describing the status; and the jqXHR (in jQuery 1.4.x, - * XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each - * function will be called in turn. This is an Ajax Event. - */ - success?: TypeOrArray>; - /** - * Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout. This - * will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the - * $.ajax call is made; if several other requests are in progress and the browser has no connections - * available, it is possible for a request to time out before it can be sent. In jQuery 1.4.x and - * below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any - * object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be - * cancelled by a timeout; the script will run even if it arrives after the timeout period. - */ - timeout?: number; - /** - * Set this to true if you wish to use the traditional style of param serialization. - */ - traditional?: boolean; - /** - * An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0. - */ - type?: string; + interface AjaxSettings extends Ajax.AjaxSettingsBase { /** * A string containing the URL to which the request is sent. */ url?: string; + } + + interface UrlAjaxSettings extends Ajax.AjaxSettingsBase { /** - * A username to be used with XMLHttpRequest in response to an HTTP access authentication request. + * A string containing the URL to which the request is sent. */ - username?: string; - /** - * 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 - * enhancements to the factory. - */ - xhr?(): XMLHttpRequest; - /** - * An object of fieldName-fieldValue pairs to set on the native XHR object. - * - * In jQuery 1.5, the withCredentials property was not propagated to the native XHR and thus CORS - * 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; + url: string; } namespace Ajax { @@ -3593,12 +3333,421 @@ declare namespace JQuery { } interface ErrorCallback { - (this: TContext, jqXHR: jqXHR, textStatus: ErrorTextStatus | null, errorThrown: string): void; + (this: TContext, jqXHR: jqXHR, textStatus: ErrorTextStatus, errorThrown: string): void; } interface CompleteCallback { (this: TContext, jqXHR: jqXHR, textStatus: TextStatus): void; } + + /** + * @see {@link http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings} + */ + interface AjaxSettingsBase { + /** + * A set of key/value pairs that map a given dataType to its MIME type, which gets sent in the Accept + * request header. This header tells the server what kind of response it will accept in return. + */ + accepts?: PlainObject; + /** + * By default, all requests are sent asynchronously (i.e. this is set to true by default). If you need + * synchronous requests, set this option to false. Cross-domain requests and dataType: "jsonp" requests + * do not support synchronous operation. Note that synchronous requests may temporarily lock the + * browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: + * false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback + * options instead of the corresponding methods of the jqXHR object such as jqXHR.done(). + */ + async?: boolean; + /** + * A pre-request callback function that can be used to modify the jqXHR (in jQuery 1.4.x, + * XMLHTTPRequest) object before it is sent. Use this to set custom headers, etc. The jqXHR and + * settings objects are passed as arguments. This is an Ajax Event. Returning false in the beforeSend + * function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless + * of the type of request. + */ + beforeSend?(this: TContext, jqXHR: jqXHR, settings: AjaxSettingsBase): false | void; + /** + * If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache + * to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}" + * to the GET parameters. The parameter is not needed for other types of requests, except in IE8 when a + * POST is made to a URL that has already been requested by a GET. + */ + cache?: boolean; + /** + * A function to be called when the request finishes (after success and error callbacks are executed). + * The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a + * string categorizing the status of the request ("success", "notmodified", "nocontent", "error", + * "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of + * functions. Each function will be called in turn. This is an Ajax Event. + */ + complete?: TypeOrArray>; + /** + * An object of string/regular-expression pairs that determine how jQuery will parse the response, + * given its content type. + */ + contents?: PlainObject; + /** + * When sending data to the server, use this content type. Default is + * "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly + * pass in a content-type to $.ajax(), then it is always sent to the server (even if no data is sent). + * As of jQuery 1.6 you can pass false to tell jQuery to not set any content type header. Note: The W3C + * XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset + * will not force the browser to change the encoding. Note: For cross-domain requests, setting the + * content type to anything other than application/x-www-form-urlencoded, multipart/form-data, or + * text/plain will trigger the browser to send a preflight OPTIONS request to the server. + */ + contentType?: string | false; + /** + * This object will be the context of all Ajax-related callbacks. By default, the context is an object + * that represents the Ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax). + */ + context?: TContext; + /** + * An object containing dataType-to-dataType converters. Each converter's value is a function that + * returns the transformed value of the response. + */ + converters?: PlainObject<((value: any) => any) | true>; + /** + * If you wish to force a crossDomain request (such as JSONP) on the same domain, set the value of + * crossDomain to true. This allows, for example, server-side redirection to another domain. + */ + crossDomain?: boolean; + /** + * Data to be sent to the server. It is converted to a query string, if not already a string. It's + * appended to the url for GET-requests. See processData option to prevent this automatic processing. + * Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same + * key based on the value of the traditional setting (described below). + */ + data?: PlainObject | string; + /** + * A function to be used to handle the raw response data of XMLHttpRequest. This is a pre-filtering + * function to sanitize the response. You should return the sanitized data. The function accepts two + * arguments: The raw data returned from the server and the 'dataType' parameter. + */ + dataFilter?(data: string, type: string): any; + /** + * The type of data that you're expecting back from the server. If none is specified, jQuery will try + * to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON + * will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be + * returned as a string). The available types (and the result passed as the first argument to your + * success callback) are: + * + * "xml": Returns a XML document that can be processed via jQuery. + * + * "html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM. + * + * "script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by + * appending a query string parameter, _=[TIMESTAMP], to the URL unless the cache option is set to + * true. Note: This will turn POSTs into GETs for remote-domain requests. + * + * "json": Evaluates the response as JSON and returns a JavaScript object. Cross-domain "json" requests + * are converted to "jsonp" unless the request includes jsonp: false in its request options. The JSON + * data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of + * jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} + * instead. (See json.org for more information on proper JSON formatting.) + * + * "jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to + * specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to + * the URL unless the cache option is set to true. + * + * "text": A plain text string. + * + * multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it + * received in the Content-Type header to what you require. For example, if you want a text response to + * be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it + * received as text, and interpreted by jQuery as XML: "jsonp text xml". Similarly, a shorthand string + * such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from + * jsonp to text, and then from text to xml. + */ + dataType?: 'xml' | 'html' | 'script' | 'json' | 'jsonp' | 'text' | string; + /** + * A function to be called if the request fails. The function receives three arguments: The jqXHR (in + * jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an + * optional exception object, if one occurred. Possible values for the second argument (besides null) + * are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives + * the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery + * 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: + * This handler is not called for cross-domain script and cross-domain JSONP requests. This is an Ajax Event. + */ + error?: TypeOrArray>; + /** + * Whether to trigger global Ajax event handlers for this request. The default is true. Set to false to + * prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to + * control various Ajax Events. + */ + global?: boolean; + /** + * An object of additional header key/value pairs to send along with requests using the XMLHttpRequest + * transport. The header X-Requested-With: XMLHttpRequest is always added, but its default + * XMLHttpRequest value can be changed here. Values in the headers setting can also be overwritten from + * within the beforeSend function. + */ + 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 + * 1.4 this technique also checks the 'etag' specified by the server to catch unmodified data. + */ + ifModified?: boolean; + /** + * Allow the current environment to be recognized as "local," (e.g. the filesystem), even if jQuery + * does not recognize it as such by default. The following protocols are currently recognized as local: + * file, *-extension, and widget. If the isLocal setting needs modification, it is recommended to do so + * once in the $.ajaxSetup() method. + */ + isLocal?: boolean; + /** + * Override the callback function name in a JSONP request. This value will be used instead of + * 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would + * result in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the jsonp option to false + * prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for + * transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, + * { jsonp: false, jsonpCallback: "callbackName" }. If you don't trust the target of your Ajax + * requests, consider setting the jsonp property to false for security reasons. + */ + jsonp?: string | false; + /** + * Specify the callback function name for a JSONP request. This value will be used instead of the + * random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name + * as it'll make it easier to manage the requests and provide callbacks and error handling. You may + * want to specify the callback when you want to enable better browser caching of GET requests. As of + * jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback + * is set to the return value of that function. + */ + jsonpCallback?: string | ((this: TContext) => string); + /** + * The HTTP method to use for the request (e.g. "POST", "GET", "PUT"). + */ + method?: string; + /** + * A mime type to override the XHR mime type. + */ + mimeType?: string; + /** + * A password to be used with XMLHttpRequest in response to an HTTP access authentication request. + */ + password?: string; + /** + * By default, data passed in to the data option as an object (technically, anything other than a + * string) will be processed and transformed into a query string, fitting to the default content-type + * "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, + * set this option to false. + */ + processData?: boolean; + /** + * Only applies when the "script" transport is used (e.g., cross-domain requests with "jsonp" or + * "script" dataType and "GET" type). Sets the charset attribute on the script tag used in the request. + * Used when the character set on the local page is not the same as the one on the remote script. + */ + scriptCharset?: string; + /** + * An object of numeric HTTP codes and functions to be called when the response has the corresponding + * code. + * + * If the request is successful, the status code functions take the same parameters as the success + * callback; if it results in an error (including 3xx redirect), they take the same parameters as the error callback. + */ + statusCode?: StatusCodeCallbacks; + /** + * A function to be called if the request succeeds. The function gets passed three arguments: The data + * returned from the server, formatted according to the dataType parameter or the dataFilter callback + * function, if specified; a string describing the status; and the jqXHR (in jQuery 1.4.x, + * XMLHttpRequest) object. As of jQuery 1.5, the success setting can accept an array of functions. Each + * function will be called in turn. This is an Ajax Event. + */ + success?: TypeOrArray>; + /** + * Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout. This + * will override any global timeout set with $.ajaxSetup(). The timeout period starts at the point the + * $.ajax call is made; if several other requests are in progress and the browser has no connections + * available, it is possible for a request to time out before it can be sent. In jQuery 1.4.x and + * below, the XMLHttpRequest object will be in an invalid state if the request times out; accessing any + * object members may throw an exception. In Firefox 3.0+ only, script and JSONP requests cannot be + * cancelled by a timeout; the script will run even if it arrives after the timeout period. + */ + timeout?: number; + /** + * Set this to true if you wish to use the traditional style of param serialization. + */ + traditional?: boolean; + /** + * An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0. + */ + type?: string; + /** + * A username to be used with XMLHttpRequest in response to an HTTP access authentication request. + */ + username?: string; + /** + * 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 + * enhancements to the factory. + */ + xhr?(): XMLHttpRequest; + /** + * An object of fieldName-fieldValue pairs to set on the native XHR object. + * + * In jQuery 1.5, the withCredentials property was not propagated to the native XHR and thus CORS + * 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; + } + + // Status codes not listed require type annotations when defining the callback + type StatusCodeCallbacks = { + // jQuery treats 2xx and 304 status codes as a success + 200?: SuccessCallback; + 201?: SuccessCallback; + 202?: SuccessCallback; + 203?: SuccessCallback; + 204?: SuccessCallback; + 205?: SuccessCallback; + 206?: SuccessCallback; + 207?: SuccessCallback; + 208?: SuccessCallback; + 209?: SuccessCallback; + 210?: SuccessCallback; + 211?: SuccessCallback; + 212?: SuccessCallback; + 213?: SuccessCallback; + 214?: SuccessCallback; + 215?: SuccessCallback; + 216?: SuccessCallback; + 217?: SuccessCallback; + 218?: SuccessCallback; + 219?: SuccessCallback; + 220?: SuccessCallback; + 221?: SuccessCallback; + 222?: SuccessCallback; + 223?: SuccessCallback; + 224?: SuccessCallback; + 225?: SuccessCallback; + 226?: SuccessCallback; + 227?: SuccessCallback; + 228?: SuccessCallback; + 229?: SuccessCallback; + 230?: SuccessCallback; + 231?: SuccessCallback; + 232?: SuccessCallback; + 233?: SuccessCallback; + 234?: SuccessCallback; + 235?: SuccessCallback; + 236?: SuccessCallback; + 237?: SuccessCallback; + 238?: SuccessCallback; + 239?: SuccessCallback; + 240?: SuccessCallback; + 241?: SuccessCallback; + 242?: SuccessCallback; + 243?: SuccessCallback; + 244?: SuccessCallback; + 245?: SuccessCallback; + 246?: SuccessCallback; + 247?: SuccessCallback; + 248?: SuccessCallback; + 249?: SuccessCallback; + 250?: SuccessCallback; + 251?: SuccessCallback; + 252?: SuccessCallback; + 253?: SuccessCallback; + 254?: SuccessCallback; + 255?: SuccessCallback; + 256?: SuccessCallback; + 257?: SuccessCallback; + 258?: SuccessCallback; + 259?: SuccessCallback; + 260?: SuccessCallback; + 261?: SuccessCallback; + 262?: SuccessCallback; + 263?: SuccessCallback; + 264?: SuccessCallback; + 265?: SuccessCallback; + 266?: SuccessCallback; + 267?: SuccessCallback; + 268?: SuccessCallback; + 269?: SuccessCallback; + 270?: SuccessCallback; + 271?: SuccessCallback; + 272?: SuccessCallback; + 273?: SuccessCallback; + 274?: SuccessCallback; + 275?: SuccessCallback; + 276?: SuccessCallback; + 277?: SuccessCallback; + 278?: SuccessCallback; + 279?: SuccessCallback; + 280?: SuccessCallback; + 281?: SuccessCallback; + 282?: SuccessCallback; + 283?: SuccessCallback; + 284?: SuccessCallback; + 285?: SuccessCallback; + 286?: SuccessCallback; + 287?: SuccessCallback; + 288?: SuccessCallback; + 289?: SuccessCallback; + 290?: SuccessCallback; + 291?: SuccessCallback; + 292?: SuccessCallback; + 293?: SuccessCallback; + 294?: SuccessCallback; + 295?: SuccessCallback; + 296?: SuccessCallback; + 297?: SuccessCallback; + 298?: SuccessCallback; + 299?: SuccessCallback; + 304?: SuccessCallback; + + // Standard 3xx, 4xx, and 5xx status codes that are considered an error + 300?: ErrorCallback; + 301?: ErrorCallback; + 302?: ErrorCallback; + 303?: ErrorCallback; + 305?: ErrorCallback; + 306?: ErrorCallback; + 307?: ErrorCallback; + 308?: ErrorCallback; + 400?: ErrorCallback; + 401?: ErrorCallback; + 402?: ErrorCallback; + 403?: ErrorCallback; + 404?: ErrorCallback; + 405?: ErrorCallback; + 406?: ErrorCallback; + 407?: ErrorCallback; + 408?: ErrorCallback; + 409?: ErrorCallback; + 410?: ErrorCallback; + 411?: ErrorCallback; + 412?: ErrorCallback; + 413?: ErrorCallback; + 414?: ErrorCallback; + 415?: ErrorCallback; + 416?: ErrorCallback; + 417?: ErrorCallback; + 418?: ErrorCallback; + 421?: ErrorCallback; + 422?: ErrorCallback; + 423?: ErrorCallback; + 424?: ErrorCallback; + 426?: ErrorCallback; + 428?: ErrorCallback; + 429?: ErrorCallback; + 431?: ErrorCallback; + 451?: ErrorCallback; + 500?: ErrorCallback; + 501?: ErrorCallback; + 502?: ErrorCallback; + 503?: ErrorCallback; + 504?: ErrorCallback; + 505?: ErrorCallback; + 506?: ErrorCallback; + 507?: ErrorCallback; + 508?: ErrorCallback; + 510?: ErrorCallback; + 511?: ErrorCallback; + } & { [index: number]: SuccessCallback | ErrorCallback; }; } interface Transport { @@ -3618,7 +3767,7 @@ declare namespace JQuery { interface jqXHR extends Pick { responseJSON: any; - statusCode(map: PlainObject | Ajax.ErrorCallback>): void; + statusCode(map: Ajax.StatusCodeCallbacks): void; /** * Add handlers to be called when the Deferred object is either resolved or rejected. @@ -3730,7 +3879,7 @@ declare namespace JQuery { } interface FailCallback { - (jqXHR: TResolve, textStatus: Ajax.ErrorTextStatus | null, errorThrown: string): void; + (jqXHR: TResolve, textStatus: Ajax.ErrorTextStatus, errorThrown: string): void; } interface AlwaysCallback { @@ -4486,7 +4635,6 @@ declare namespace JQuery { interface JQueryCallback extends JQuery.Callbacks { } interface JQueryDeferred extends JQuery.Deferred { } -interface JQueryEventObject extends JQuery.Event { } interface JQueryEventConstructor extends JQuery.Event { } interface JQueryDeferred extends JQuery.Deferred { } interface JQueryAjaxSettings extends JQuery.AjaxSettings { } @@ -4649,6 +4797,10 @@ interface JQueryKeyEventObject extends JQueryInputEventObject { key: any; keyCode: number; } +/** + * @deprecated + */ +interface JQueryEventObject extends BaseJQueryEventObject, JQueryInputEventObject, JQueryMouseEventObject, JQueryKeyEventObject { } /** * @deprecated */ diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index c31352cb02..438f36c79b 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1277,7 +1277,9 @@ function JQuery() { // $ExpectType JQuery $('p').show(); } + } + function queue() { function clearQueue() { // $ExpectType JQuery $('p').clearQueue('myQueue'); @@ -1379,6 +1381,17 @@ function JQuery() { // $ExpectType JQuery $('p').stop(true); } + + function promise() { + // $ExpectType { description: string; } & Promise, any, any> + $('p').promise('myQueue', { description: 'desc' }); + + // $ExpectType { description: string; } & Promise, any, any> + $('p').promise({ description: 'desc' }); + + // $ExpectType Promise, any, any> + $('p').promise(); + } } function events() { @@ -2403,6 +2416,1057 @@ function JQuery() { }); } } + + function manipulation() { + function after() { + // $ExpectType JQuery + $('p').after('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function append() { + // $ExpectType JQuery + $('p').append('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + + // $ExpectType JQuery + $('p').append($.parseHTML('myTextNode ')); + } + + function before() { + // $ExpectType JQuery + $('p').before('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function prepend() { + // $ExpectType JQuery + $('p').prepend('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function appendTo() { + // $ExpectType JQuery + $('span').appendTo('p'); + + // $ExpectType JQuery + $('span').appendTo('

'); + + // $ExpectType JQuery + $('span').appendTo(new HTMLElement()); + + // $ExpectType JQuery + $('span').appendTo([new HTMLElement()]); + + // $ExpectType JQuery + $('span').appendTo($('p')); + } + + function insertAfter() { + // $ExpectType JQuery + $('span').insertAfter('p'); + + // $ExpectType JQuery + $('span').insertAfter('

'); + + // $ExpectType JQuery + $('span').insertAfter(new HTMLElement()); + + // $ExpectType JQuery + $('span').insertAfter([new HTMLElement()]); + + // $ExpectType JQuery + $('span').insertAfter($('p')); + } + + function insertBefore() { + // $ExpectType JQuery + $('span').insertBefore('p'); + + // $ExpectType JQuery + $('span').insertBefore('

'); + + // $ExpectType JQuery + $('span').insertBefore(new HTMLElement()); + + // $ExpectType JQuery + $('span').insertBefore([new HTMLElement()]); + + // $ExpectType JQuery + $('span').insertBefore($('p')); + } + + function prependTo() { + // $ExpectType JQuery + $('span').prependTo('p'); + + // $ExpectType JQuery + $('span').prependTo('

'); + + // $ExpectType JQuery + $('span').prependTo(new HTMLElement()); + + // $ExpectType JQuery + $('span').prependTo([new HTMLElement()]); + + // $ExpectType JQuery + $('span').prependTo($('p')); + } + + function clone() { + // $ExpectType JQuery + $('p').clone(true, true); + + // $ExpectType JQuery + $('p').clone(true); + + // $ExpectType JQuery + $('p').clone(); + } + + function detach() { + // $ExpectType JQuery + $('p').detach('span'); + + // $ExpectType JQuery + $('p').detach(); + } + + function empty() { + // $ExpectType JQuery + $('p').empty(); + } + + function remove() { + // $ExpectType JQuery + $('p').remove('span'); + + // $ExpectType JQuery + $('p').remove(); + } + + function replaceAll() { + // $ExpectType JQuery + $('p').replaceAll('span'); + + // $ExpectType JQuery + $('p').replaceAll($('span')); + + // $ExpectType JQuery + $('p').replaceAll(new HTMLElement()); + + // $ExpectType JQuery + $('p').replaceAll([new HTMLElement()]); + } + + function replaceWith() { + // $ExpectType JQuery + $('p').replaceWith(''); + + // $ExpectType JQuery + $('p').replaceWith($('span')); + + // $ExpectType JQuery + $('p').replaceWith(new HTMLElement()); + + // $ExpectType JQuery + $('p').replaceWith([new HTMLElement()]); + + // $ExpectType JQuery + $('p').replaceWith(function() { + // $ExpectType HTMLElement + this; + + return this; + }); + } + + function unwrap() { + // $ExpectType JQuery + $('p').unwrap('span'); + + // $ExpectType JQuery + $('p').unwrap(); + } + + function wrap() { + // $ExpectType JQuery + $('p').wrap('span'); + + // $ExpectType JQuery + $('p').wrap(''); + + // $ExpectType JQuery + $('p').wrap(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrap($('span')); + + // $ExpectType JQuery + $('p').wrap(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrap(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return $('span'); + }); + } + + function wrapAll() { + // $ExpectType JQuery + $('p').wrapAll('span'); + + // $ExpectType JQuery + $('p').wrapAll(''); + + // $ExpectType JQuery + $('p').wrapAll(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrapAll($('span')); + + // $ExpectType JQuery + $('p').wrapAll(function() { + // $ExpectType HTMLElement + this; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrapAll(function() { + // $ExpectType HTMLElement + this; + + return $('span'); + }); + } + + function wrapInner() { + // $ExpectType JQuery + $('p').wrapInner('span'); + + // $ExpectType JQuery + $('p').wrapInner(''); + + // $ExpectType JQuery + $('p').wrapInner(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrapInner($('span')); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return $('span'); + }); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return new HTMLElement(); + }); + } + + function html() { + // $ExpectType JQuery + $('p').html(''); + + // $ExpectType JQuery + $('p').html(function(index, oldhtml) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + oldhtml; + + return oldhtml; + }); + + // $ExpectType string + $('p').html(); + } + + function text() { + // $ExpectType JQuery + $('p').text('myText'); + + // $ExpectType JQuery + $('p').text(4); + + // $ExpectType JQuery + $('p').text(true); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return 'myText'; + }); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return 3; + }); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return false; + }); + + // $ExpectType string + $('p').text(); + } + + function val() { + // $ExpectType JQuery + $('p').val('myVal'); + + // $ExpectType JQuery + $('p').val(5); + + // $ExpectType JQuery + $('p').val(['myVal']); + + // $ExpectType JQuery + $('p').val(function(index, value) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + value; + + return 'myVal'; + }); + + // $ExpectType string | number | string[] | null | undefined + $('p').val(); + } + } + + function traversing() { + function add() { + // $ExpectType JQuery + $('p').add('span', new HTMLElement()); + + // $ExpectType JQuery + $('p').add('span'); + + // $ExpectType JQuery + $('p').add(new HTMLElement()); + + // $ExpectType JQuery + $('p').add([new HTMLElement()]); + + // $ExpectType JQuery + $('p').add(''); + + // $ExpectType JQuery + $('p').add($('span')); + } + + function closest() { + // $ExpectType JQuery + $('p').closest('span', new HTMLElement()); + + // $ExpectType JQuery + $('p').closest('span'); + + // $ExpectType JQuery + $('p').closest(new HTMLElement()); + + // $ExpectType JQuery + $('p').closest($('span')); + } + + function find() { + // $ExpectType JQuery + $('p').find('span'); + + // $ExpectType JQuery + $('p').find(new HTMLElement()); + + // $ExpectType JQuery + $('p').find($('span')); + } + + function addBack() { + // $ExpectType JQuery + $('p').addBack('span'); + + // $ExpectType JQuery + $('p').addBack(); + } + + function children() { + // $ExpectType JQuery + $('p').children('span'); + + // $ExpectType JQuery + $('p').children(); + } + + function siblings() { + // $ExpectType JQuery + $('p').siblings('span'); + + // $ExpectType JQuery + $('p').siblings(); + } + + function contents() { + // $ExpectType JQuery + $('p').contents(); + } + + function end() { + // $ExpectType JQuery + $('p').end(); + } + + function first() { + // $ExpectType JQuery + $('p').first(); + } + + function last() { + // $ExpectType JQuery + $('p').last(); + } + + function offsetParent() { + // $ExpectType JQuery + $('p').offsetParent(); + } + + function filter() { + // $ExpectType JQuery + $('p').filter('span'); + + // $ExpectType JQuery + $('p').filter(new HTMLElement()); + + // $ExpectType JQuery + $('p').filter([new HTMLElement()]); + + // $ExpectType JQuery + $('p').filter($('span')); + + // $ExpectType JQuery + $('p').filter(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function not() { + // $ExpectType JQuery + $('p').not('span'); + + // $ExpectType JQuery + $('p').not(new HTMLElement()); + + // $ExpectType JQuery + $('p').not([new HTMLElement()]); + + // $ExpectType JQuery + $('p').not($('span')); + + // $ExpectType JQuery + $('p').not(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function is() { + // $ExpectType boolean + $('p').is('span'); + + // $ExpectType boolean + $('p').is(new HTMLElement()); + + // $ExpectType boolean + $('p').is([new HTMLElement()]); + + // $ExpectType boolean + $('p').is($('span')); + + // $ExpectType boolean + $('p').is(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function next() { + // $ExpectType JQuery + $('p').next('span'); + + // $ExpectType JQuery + $('p').next(); + } + + function nextAll() { + // $ExpectType JQuery + $('p').nextAll('span'); + + // $ExpectType JQuery + $('p').nextAll(); + } + + function nextUntil() { + // $ExpectType JQuery + $('p').nextUntil('span', 'span'); + + // $ExpectType JQuery + $('p').nextUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').nextUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').nextUntil('span'); + + // $ExpectType JQuery + $('p').nextUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').nextUntil($('span')); + + // $ExpectType JQuery + $('p').nextUntil(); + } + + function prev() { + // $ExpectType JQuery + $('p').prev('span'); + + // $ExpectType JQuery + $('p').prev(); + } + + function prevAll() { + // $ExpectType JQuery + $('p').prevAll('span'); + + // $ExpectType JQuery + $('p').prevAll(); + } + + function prevUntil() { + // $ExpectType JQuery + $('p').prevUntil('span', 'span'); + + // $ExpectType JQuery + $('p').prevUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').prevUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').prevUntil('span'); + + // $ExpectType JQuery + $('p').prevUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').prevUntil($('span')); + + // $ExpectType JQuery + $('p').prevUntil(); + } + + function parent() { + // $ExpectType JQuery + $('p').parent('span'); + + // $ExpectType JQuery + $('p').parent(); + } + + function parents() { + // $ExpectType JQuery + $('p').parents('span'); + + // $ExpectType JQuery + $('p').parents(); + } + + function parentsUntil() { + // $ExpectType JQuery + $('p').parentsUntil('span', 'span'); + + // $ExpectType JQuery + $('p').parentsUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').parentsUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').parentsUntil('span'); + + // $ExpectType JQuery + $('p').parentsUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').parentsUntil($('span')); + + // $ExpectType JQuery + $('p').parentsUntil(); + } + + function eq() { + // $ExpectType JQuery + $('p').eq(0); + } + + function has() { + // $ExpectType JQuery + $('p').has('span'); + + // $ExpectType JQuery + $('p').has(new HTMLElement()); + } + + function map() { + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return 'myVal'; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return ['myVal1', 'myVal2']; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return null; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return undefined; + }); + } + + function slice() { + // $ExpectType JQuery + $('p').slice(0, 10); + + // $ExpectType JQuery + $('p').slice(0); + } + + function pushStack() { + // $ExpectType JQuery + $('p').pushStack([new HTMLElement()], 'name', ['arg']); + + // $ExpectType JQuery + $('p').pushStack([new HTMLElement()]); + } + } + + function misc() { + function serialize() { + // $ExpectType string + $('p').serialize(); + } + + function serializeArray() { + // $ExpectType NameValuePair[] + $('p').serializeArray(); + } + + function each() { + // $ExpectType JQuery + $('p').each(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + }); + + // $ExpectType JQuery + $('p').each(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function extend() { + // $ExpectType JQuery + $.fn.extend({ myPlugin: {} }); + } + + function get() { + // $ExpectType HTMLElement + $('p').get(0); + + // $ExpectType HTMLElement[] + $('p').get(); + } + + function index() { + // $ExpectType number + $('p').index('span'); + + // $ExpectType number + $('p').index(new HTMLElement()); + + // $ExpectType number + $('p').index($('span')); + + // $ExpectType number + $('p').index(); + } + + function toArray() { + // $ExpectType HTMLElement[] + $('p').toArray(); + } + } } function JQueryStatic() { @@ -2414,18 +3478,65 @@ function JQueryStatic() { const jq: JQueryStatic = $; } - function constructor() { - function selector_object_callback() { - const jq = $ as JQueryStatic; - // $ExpectType JQuery - jq('div'); - } + function call_signature() { + // #ExpectType JQuery + $('

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

', { + class: 'my-div', + on: { + touchstart() { + // Do something + } + } + }); + + // #ExpectType JQuery + $('span', new HTMLElement()); + + // #ExpectType JQuery + $('span', new Document()); + + // #ExpectType JQuery + $('span', $('p')); + + // #ExpectType JQuery + $('span'); + + // #ExpectType JQuery + $('

'); + + // #ExpectType JQuery + $(new HTMLElement()); + + // #ExpectType JQuery + $([new HTMLElement()]); + + // #ExpectType JQuery + $({ foo: 'bar', hello: 'world' }); + + // #ExpectType JQuery + $($('p')); + + // #ExpectType JQuery + $(function($) { + // #ExpectType Document + this; + // #ExpectType JQueryStatic + $; + }); + + // #ExpectType JQuery + $(); } function Callbacks() { - const cb = $.Callbacks(); + // #ExpectType Callbacks + $.Callbacks('once'); - cb.add(console.log); + // #ExpectType Callbacks + $.Callbacks(); } function Event() { @@ -2435,26 +3546,468 @@ function JQueryStatic() { } } + function ajax() { + // $ExpectType jqXHR + $.ajax('url', { + cache: true + }); + } + + function ajaxPrefilter() { + // $ExpectType void + $.ajaxPrefilter('dataTypes', (options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + + return 'filtered'; + }); + + // $ExpectType void + $.ajaxPrefilter('dataTypes', (options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType void + $.ajaxPrefilter((options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + + return 'filtered'; + }); + + // $ExpectType void + $.ajaxPrefilter((options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + }); + } + + function ajaxSetup() { + // $ExpectType AjaxSettings + $.ajaxSetup({ + cache: true + }); + } + + function ajaxTransport() { + // $ExpectType void + $.ajaxTransport('dataTypes', (options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + + return { + send(headers, completeCallback) { + // $ExpectType PlainObject + headers; + // $ExpectType SuccessCallback + completeCallback; + }, + abort() { } + }; + }); + + // $ExpectType void + $.ajaxTransport('dataTypes', (options, originalOptions, jqXHR) => { + // $ExpectType AjaxSettings + options; + // $ExpectType AjaxSettings + originalOptions; + // $ExpectType jqXHR + jqXHR; + }); + } + + function contains() { + // $ExpectType boolean + $.contains(new HTMLElement(), new HTMLElement()); + } + + function css() { + // $ExpectType any + $.css(new HTMLElement(), {}); + } + + function data() { + // $ExpectType any + $.data(new HTMLElement(), 'myKey', undefined); + + // $ExpectType "myValue" + $.data(new HTMLElement(), 'myKey', 'myValue'); + + // $ExpectType any + $.data(new HTMLElement(), 'myKey'); + + // $ExpectType any + $.data(new HTMLElement()); + } + + function dequeue() { + // $ExpectType void + $.dequeue(new HTMLElement(), 'myQueue'); + + // $ExpectType void + $.dequeue(new HTMLElement()); + } + function each() { - function arrayLike() { - $.each({ length: 3 }, (index, val) => { - index === 3; - }); - } + // $ExpectType ArrayLike + $.each(['myVal1', 'myVal2'], function(index, val) { + // $ExpectType string + this; + // $ExpectType number + index; + // $ExpectType string + val; + + return false; + }); + + // $ExpectType ArrayLike + $.each(['myVal1', 'myVal2'], function(index, val) { + // $ExpectType string + this; + // $ExpectType number + index; + // $ExpectType string + val; + + return 10; + }); + + // $ExpectType ArrayLike + $.each(['myVal1', 'myVal2'], function(index, val) { + // $ExpectType string + this; + // $ExpectType number + index; + // $ExpectType string + val; + }); + + // $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; } + $.each({ + myVal1: false, + myVal2: () => { + return 10; + }, + myVal3: 'myVal3' + }, function(propertyName, valueOfProperty) { + // $ExpectType string | boolean | (() => 10) + this; + // $ExpectType "myVal1" | "myVal2" | "myVal3" + propertyName; + // $ExpectType string | boolean | (() => 10) + valueOfProperty; + + return false; + }); + + // $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; } + $.each({ + myVal1: false, + myVal2: () => { + return 10; + }, + myVal3: 'myVal3' + }, function(propertyName, valueOfProperty) { + // $ExpectType string | boolean | (() => 10) + this; + // $ExpectType "myVal1" | "myVal2" | "myVal3" + propertyName; + // $ExpectType string | boolean | (() => 10) + valueOfProperty; + + return 10; + }); + + // $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; } + $.each({ + myVal1: false, + myVal2: () => { + return 10; + }, + myVal3: 'myVal3' + }, function(propertyName, valueOfProperty) { + // $ExpectType string | boolean | (() => 10) + this; + // $ExpectType "myVal1" | "myVal2" | "myVal3" + propertyName; + // $ExpectType string | boolean | (() => 10) + valueOfProperty; + }); + } + + function error() { + jQuery.error = console.error; + } + + function escapeSelector() { + // $ExpectType string + $.escapeSelector('span'); + } + + function extend() { + const t = { name: 'myObj' }; + const u = new EventTarget(); + const v = new Node(); + const w = new Comment(); + const x = new Text(); + const y = new Element(); + const z = new HTMLElement(); + const a = new SVGElement(); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element & HTMLElement + $.extend(true, t, u, v, w, x, y, z); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element + $.extend(true, t, u, v, w, x, y); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text + $.extend(true, t, u, v, w, x); + + // $ExpectType { name: string; } & EventTarget & Node & Comment + $.extend(true, t, u, v, w); + + // $ExpectType { name: string; } & EventTarget & Node + $.extend(true, t, u, v); + + // $ExpectType { name: string; } & EventTarget + $.extend(true, t, u); + + // $ExpectType any + $.extend(true, t, u, v, w, x, y, z, a); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element & HTMLElement + $.extend(t, u, v, w, x, y, z); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element + $.extend(t, u, v, w, x, y); + + // $ExpectType { name: string; } & EventTarget & Node & Comment & Text + $.extend(t, u, v, w, x); + + // $ExpectType { name: string; } & EventTarget & Node & Comment + $.extend(t, u, v, w); + + // $ExpectType { name: string; } & EventTarget & Node + $.extend(t, u, v); + + // $ExpectType { name: string; } & EventTarget + $.extend(t, u); + + // $ExpectType any + $.extend(t, u, v, w, x, y, z, a); + } + + function get() { + // $ExpectType jqXHR + $.get('url', { myData: 'myData' }, (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.get('url', 'myData', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.get('url', { myData: 'myData' }, null, 'script'); + + // $ExpectType jqXHR + $.get('url', 'myData', null, 'script'); + + // $ExpectType jqXHR + $.get('url', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.get('url', null, 'script'); + + // $ExpectType jqXHR + $.get('url', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.get('url', { myData: 'myData' }); + + // $ExpectType jqXHR + $.get('url', 'myData'); + + // $ExpectType jqXHR + $.get('url'); + + // $ExpectType jqXHR + $.get({ url: 'url' }); + + // $ExpectType jqXHR + $.get(); + } + + function getJSON() { + // $ExpectType jqXHR + $.getJSON('url', { myVal1: 'myVal1' }, (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.getJSON('url', 'myVal1', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.getJSON('url', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + + // $ExpectType jqXHR + $.getJSON('url', { myVal1: 'myVal1' }); + + // $ExpectType jqXHR + $.getJSON('url', 'myVal1'); + + // $ExpectType jqXHR + $.getJSON('url'); + } + + function getScript() { + // $ExpectType jqXHR + $.getScript('url', (data, textStatus, jqXHR) => { + // $ExpectType string | undefined + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }); + } + + function globalEval() { + // $ExpectType void + $.globalEval('throw new Error();'); + } + + function grep() { + // $ExpectType string[] + $.grep(['myVal1', 'myVal2'], (elementOfArray, indexInArray) => { + // $ExpectType string + elementOfArray; + // $ExpectType number + indexInArray; + + return true; + }, true); + + // $ExpectType string[] + $.grep(['myVal1', 'myVal2'], (elementOfArray, indexInArray) => { + // $ExpectType string + elementOfArray; + // $ExpectType number + indexInArray; + + return true; + }); + } + + function hasData() { + // $ExpectType boolean + $.hasData(new HTMLElement()); + } + + function holdReady() { + // $ExpectType void + $.holdReady(true); + } + + function htmlPrefilter() { + // $ExpectType string + $.htmlPrefilter(''); + } + + function inArray() { + // $ExpectType number + $.inArray(1, [1, 2], 1); + + // $ExpectType number + $.inArray(1, [1, 2]); } function isArray() { function type_guard(obj: object) { if ($.isArray(obj)) { - console.log(obj[0]); + // $ExpectType any[] + obj; } } } + function isEmptyObject() { + // $ExpectType boolean + $.isEmptyObject({}); + } + function isFunction() { function type_guard(obj: object) { if ($.isFunction(obj)) { - obj(); + // $ExpectType Function + obj; } } } @@ -2462,7 +4015,8 @@ function JQueryStatic() { function isNumeric() { function type_guard(obj: boolean) { if ($.isNumeric(obj)) { - obj.toFixed(); + // $ExpectType (true & number) | (false & number) + obj; } } } @@ -2470,7 +4024,8 @@ function JQueryStatic() { function isPlainObject() { function type_guard(obj: object) { if ($.isPlainObject(obj)) { - obj['key'] = true; + // $ExpectType PlainObject + obj; } } } @@ -2478,37 +4033,239 @@ function JQueryStatic() { function isWindow() { function type_guard(obj: object) { if ($.isWindow(obj)) { - obj.location.href === 'href'; + // $ExpectType Window + obj; } } } + function isXMLDoc() { + // $ExpectType boolean + $.isXMLDoc(new Node()); + } + + function makeArray() { + // $ExpectType number[] + $.makeArray([1, 2]); + } + function map() { - function object() { - const testObj = { - myProp: true, - name: 'Rogers', - }; + // $ExpectType number[] + $.map([1, 2, 3], (elementOfArray, indexInArray) => { + // $ExpectType number + elementOfArray; + // $ExpectType number + indexInArray; - const results = $.map(testObj, (propertyOfObject, key) => { - switch (key) { - case 'myProp': - return 1; - case 'name': - return false; - } - }); + return 200 + 10; + }); - for (const result of results) { - result === 1; + // $ExpectType (false | 1)[] + $.map({ + myProp: true, + name: 'Rogers', + }, (propertyOfObject, key) => { + // $ExpectType string | boolean + propertyOfObject; + // $ExpectType "myProp" | "name" + key; + + switch (key) { + case 'myProp': + return 1; + case 'name': + return false; } - } + }); + } + + function merge() { + // $ExpectType (string | number)[] + $.merge([1, 2, 3], ['myVal1', 'myVal2']); + } + + function noConflict() { + // $ExpectType JQueryStatic + $.noConflict(true); + + // $ExpectType JQueryStatic + $.noConflict(); + } + + function noop() { + // $ExpectType undefined + $.noop(); + } + + function now() { + // $ExpectType number + $.now(); + } + + function param() { + // $ExpectType string + $.param([true, 20], true); + + // $ExpectType string + $.param({ + myVal1: true, + myVal2: 20 + }, true); + + // $ExpectType string + $.param($('input'), true); + + // $ExpectType string + $.param([true, 20]); + + // $ExpectType string + $.param({ + myVal1: true, + myVal2: 20 + }); + + // $ExpectType string + $.param($('input')); + } + + function parseHTML() { + // $ExpectType Node[] + $.parseHTML('', document, true); + + // $ExpectType Node[] + $.parseHTML('', null, true); + + // $ExpectType Node[] + $.parseHTML('', undefined, true); + + // $ExpectType Node[] + $.parseHTML('', document); + + // $ExpectType Node[] + $.parseHTML('', null); + + // $ExpectType Node[] + $.parseHTML('', undefined); + + // $ExpectType Node[] + $.parseHTML('', false); + + // $ExpectType Node[] + $.parseHTML(''); + } + + function parseJSON() { + // $ExpectType any + $.parseJSON('{}'); + } + + function parseXML() { + // $ExpectType XMLDocument + $.parseXML(''); + } + + function post() { + // $ExpectType jqXHR + $.post('url', { myData: 'myData' }, (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.post('url', 'myData', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.post('url', { myData: 'myData' }, null, 'script'); + + // $ExpectType jqXHR + $.post('url', 'myData', null, 'script'); + + // $ExpectType jqXHR + $.post('url', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.post('url', null, 'script'); + + // $ExpectType jqXHR + $.post('url', (data, textStatus, jqXHR) => { + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, 'script'); + + // $ExpectType jqXHR + $.post('url', { myData: 'myData' }); + + // $ExpectType jqXHR + $.post('url', 'myData'); + + // $ExpectType jqXHR + $.post('url'); + + // $ExpectType jqXHR + $.post({ url: 'url' }); + + // $ExpectType jqXHR + $.post(); + } + + function proxy() { + // $ExpectType Function + $.proxy($.noop, {}, 1, 2); + + // $ExpectType Function + $.proxy($.noop, {}); + + // $ExpectType Function + $.proxy({ myFunc: $.noop }, 'myFunc', 1, 2); + + // $ExpectType Function + $.proxy({ myFunc: $.noop }, 'myFunc'); } function queue() { - const el = new HTMLElement(); - const queue = jQuery.queue(el); - queue[0] === 'inprogress'; + // $ExpectType Queue + $.queue(new HTMLElement(), 'myQueue', function(next) { + // $ExpectType HTMLElement + this; + // $ExpectType () => void + next; + }); + + // $ExpectType Queue + $.queue(new HTMLElement(), 'myQueue', [function(next) { + // $ExpectType HTMLElement + this; + // $ExpectType () => void + next; + }]); + + // $ExpectType Queue + $.queue(new HTMLElement(), 'myQueue'); + + // $ExpectType Queue + $.queue(new HTMLElement()); } function readyException() { @@ -2516,6 +4273,260 @@ function JQueryStatic() { console.error(error); }; } + + function removeData() { + // $ExpectType void + $.removeData(new HTMLElement(), 'test1'); + + // $ExpectType void + $.removeData(new HTMLElement()); + } + + function speed() { + // $ExpectType EffectsOptions + $.speed(5000, 'linear', function() { + // $ExpectType HTMLElement + this; + }); + + // $ExpectType EffectsOptions + $.speed(5000, 'linear'); + + // $ExpectType EffectsOptions + $.speed(5000, function() { + // $ExpectType HTMLElement + this; + }); + + // $ExpectType EffectsOptions + $.speed(5000); + + // $ExpectType EffectsOptions + $.speed(function() { + // $ExpectType HTMLElement + this; + }); + + // $ExpectType EffectsOptions + $.speed({ + duration: 5000, + easing: 'linear', + complete() { + // $ExpectType HTMLElement + this; + } + }); + + // $ExpectType EffectsOptions + $.speed(); + } + + function trim() { + // $ExpectType string + $.trim('myStr'); + } + + function type() { + // $ExpectType "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" | "error" | "array" | "date" | "null" | "regexp" + $.type({}); + } + + function unique() { + // $ExpectType HTMLElement[] + $.unique([new HTMLElement()]); + } + + function uniqueSort() { + // $ExpectType HTMLElement[] + $.uniqueSort([new HTMLElement()]); + } + + function when() { + const t = $.ajax() as JQuery.jqXHR; + const u = $.ajax() as JQuery.jqXHR; + const v = $.ajax() as JQuery.jqXHR; + + // $ExpectType Promise<[string | number | boolean, string, jqXHR], any, any> + $.when(t, u, v); + + // $ExpectType Promise<[string | number, string, jqXHR], any, any> + $.when(t, u); + + // $ExpectType Promise, any, any> + $.when(t); + + // $ExpectType Promise + $.when($.Deferred()); + + // $ExpectType Promise + $.when(); + } +} + +function AjaxSettings() { + $.ajax({ + accepts: { + mycustomtype: 'application/x-some-custom-type' + }, + async: true, + beforeSend(jqXHR, settings) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType AjaxSettingsBase + settings; + }, + cache: false, + complete(jqXHR, textStatus) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType TextStatus + textStatus; + }, + contents: { + mycustomtype: /mycustomtype/ + }, + contentType: 'application/x-some-custom-type', + converters: { + 'text mycustomtype': true, + 'mycustomtype json': (result) => { + // $ExpectType any + result; + + return result; + } + }, + crossDomain: false, + data: { + myData: 'myData' + }, + dataFilter(data, type) { + // $ExpectType string + data; + // $ExpectType string + type; + + return 'filtered'; + }, + dataType: 'mycustomtype', + error(jqXHR, textStatus, errorThrown) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }, + global: true, + headers: { + 'X-Requested-With': 'XMLHttpRequest' + }, + ifModified: false, + isLocal: true, + jsonp: 'callback', + jsonpCallback: 'callback', + method: 'PUT', + mimeType: 'mimeType', + password: 'hunter2', + processData: false, + scriptCharset: 'scriptCharset', + statusCode: { + 200(data, textStatus, jqXHR) { + // $ExpectType any + this; + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, + 404(jqXHR, textStatus, errorThrown) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + } + }, + success(data, textStatus, jqXHR) { + // $ExpectType any + this; + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }, + timeout: 10, + traditional: true, + username: 'username', + xhr() { + return new XMLHttpRequest(); + }, + xhrFields: { + withCredentials: true + } + }); + + $.ajax({ + beforeSend(jqXHR, settings) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType AjaxSettingsBase + settings; + + return false; + }, + complete: [function(jqXHR, textStatus) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType TextStatus + textStatus; + }], + contentType: false, + data: 'myData', + error: [function(jqXHR, textStatus, errorThrown) { + // $ExpectType any + this; + // $ExpectType jqXHR + jqXHR; + // $ExpectType ErrorTextStatus + textStatus; + // $ExpectType string + errorThrown; + }], + jsonp: false, + jsonpCallback() { + // $ExpectType any + this; + + return 'callback'; + }, + success: [function(data, textStatus, jqXHR) { + // $ExpectType any + this; + // $ExpectType any + data; + // $ExpectType SuccessTextStatus + textStatus; + // $ExpectType jqXHR + jqXHR; + }] + }); } function EffectsOptions() { @@ -2629,9 +4640,7 @@ function jqXHR() { $.ajax('/echo').fail((jqXHR, textStatus, errorThrown) => { // $ExpectType jqXHR jqXHR; - // This test is flaky - // Should be 'ErrorTextStatus | null' and should be able to handle it out of order - // $ExpectType "timeout" | "error" | "abort" | "parsererror" | null + // $ExpectType ErrorTextStatus textStatus; // $ExpectType string errorThrown; diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 961e239192..404aba2013 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -2434,7 +2434,7 @@ function examples() { } function jQuery_error_0() { - jQuery.error = console.error as any; + jQuery.error = console.error; } function jQuery_escape_selector_0() { @@ -2907,7 +2907,7 @@ function examples() { function jQuery_parse_html_0() { var $log = $('#log'), str = 'hello, my name is jQuery.', - html = $.parseHTML(str) as HTMLElement[], + html = $.parseHTML(str), nodeNames: string[] = []; // Append the parsed HTML @@ -4056,7 +4056,7 @@ function examples() { function promise_0() { var div = $('
'); - div.promise().done(function(this: JQuery, arg1: JQuery) { + div.promise().done(function(this: typeof div, arg1) { // Will fire right away and alert "true" alert(this === div && arg1 === div); }); diff --git a/types/knex/index.d.ts b/types/knex/index.d.ts index 2e301af850..a7c08661d2 100644 --- a/types/knex/index.d.ts +++ b/types/knex/index.d.ts @@ -177,9 +177,8 @@ declare namespace Knex { interface Join { (raw: Raw): QueryBuilder; - (builder: QueryBuilder, clause: (this: JoinClause) => void): QueryBuilder; - (tableName: string, columns: { [key: string]: string | number | Raw }): QueryBuilder; - (tableName: string, callback: Function): QueryBuilder; + (tableName: TableName, clause: (this: JoinClause) => void): QueryBuilder; + (tableName: TableName, columns: { [key: string]: string | number | Raw }): QueryBuilder; (tableName: TableName, raw: Raw): QueryBuilder; (tableName: TableName, column1: string, column2: string): QueryBuilder; (tableName: TableName, column1: string, raw: Raw): QueryBuilder; diff --git a/types/knex/knex-tests.ts b/types/knex/knex-tests.ts index 1f12a1044a..610f51cc1f 100644 --- a/types/knex/knex-tests.ts +++ b/types/knex/knex-tests.ts @@ -213,6 +213,14 @@ knex('users') .join(knex('contacts').select('user_id', 'phone').as('contacts'), 'users.id', 'contacts.user_id') .select('users.id', 'contacts.phone'); +knex('users') + .join(knex('contacts').select('user_id', 'phone').as('contacts'), { 'users.id': 'contacts.user_id' }) + .select('users.id', 'contacts.phone'); + +knex.select('*').from('users').join(knex('accounts').select('id', 'owner_id').as('accounts'), function() { + this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') +}); + knex.select('*').from('users').join('accounts', function() { this.on('accounts.id', '=', 'users.account_id').orOn('accounts.owner_id', '=', 'users.id') }); diff --git a/types/mongoose-simple-random/index.d.ts b/types/mongoose-simple-random/index.d.ts new file mode 100644 index 0000000000..cf41c64241 --- /dev/null +++ b/types/mongoose-simple-random/index.d.ts @@ -0,0 +1,13 @@ +// Type definitions for mongoose-simple-random 0.4 +// Project: https://github.com/larryprice/mongoose-simple-random +// Definitions by: My Self +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +// tslint:disable-next-line no-single-declare-module +declare module "mongoose" { + interface Model extends NodeJS.EventEmitter, ModelProperties { + findRandom(conditions: Object, projection?: Object | null, options?: Object | null, callback?: (err: any, res: T[]) => void) + : void; + } +} diff --git a/types/mongoose-simple-random/mongoose-simple-random-tests.ts b/types/mongoose-simple-random/mongoose-simple-random-tests.ts new file mode 100644 index 0000000000..2aa9e18296 --- /dev/null +++ b/types/mongoose-simple-random/mongoose-simple-random-tests.ts @@ -0,0 +1,15 @@ +import * as mongoose from 'mongoose'; + +// test compatibility with other libraries - from @types/mongoose +import * as _ from 'lodash'; +import * as fs from "fs"; + +mongoose.Model.findRandom({ + username: { $ne: "DummyUser" }, + rating: { + $gt: 1, + $lt: 11, + }, +}, {}, { limit: 1 }, (error, data) => { + if (error) { console.error("Error!"); } else { console.log("Success!"); } +}); diff --git a/types/mongoose-simple-random/tsconfig.json b/types/mongoose-simple-random/tsconfig.json new file mode 100644 index 0000000000..28627f97dd --- /dev/null +++ b/types/mongoose-simple-random/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mongoose-simple-random-tests.ts" + ] +} diff --git a/types/mongoose-simple-random/tslint.json b/types/mongoose-simple-random/tslint.json new file mode 100644 index 0000000000..8438350251 --- /dev/null +++ b/types/mongoose-simple-random/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + // This package uses the Function type, and it will take effort to fix. + "ban-types": false + } +} \ No newline at end of file diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 952cf98e4d..131dbc96a1 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -761,13 +761,14 @@ declare module "http" { import * as events from "events"; import * as net from "net"; import * as stream from "stream"; + import { URL } from "url"; export interface RequestOptions { protocol?: string; host?: string; hostname?: string; family?: number; - port?: number; + port?: number | string; localAddress?: string; socketPath?: string; method?: string; @@ -935,8 +936,8 @@ declare module "http" { }; export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) => void): Server; export function createClient(port?: number, host?: string): any; - export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; - export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; + export function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; + export function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; export var globalAgent: Agent; } @@ -1492,6 +1493,7 @@ declare module "https" { import * as tls from "tls"; import * as events from "events"; import * as http from "http"; + import { URL } from "url"; export interface ServerOptions { pfx?: any; @@ -1544,8 +1546,8 @@ declare module "https" { }; export interface Server extends tls.Server { } export function createServer(options: ServerOptions, requestListener?: (req: IncomingMessage, res: ServerResponse) => void): Server; - export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; - export function get(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; + export function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; + export function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; export var globalAgent: Agent; } diff --git a/types/react-burger-menu/index.d.ts b/types/react-burger-menu/index.d.ts new file mode 100644 index 0000000000..6d3a508c97 --- /dev/null +++ b/types/react-burger-menu/index.d.ts @@ -0,0 +1,57 @@ +// Type definitions for react-burger-menu 2.1 +// Project: https://github.com/negomi/react-burger-menu +// Definitions by: Rajab Shakirov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as React from "react"; + +// TODO (Rajab) actually I don't want export Props, but +// `npm run lint react-burger-menu` error doesn't allow me to do it; +export interface Props { + burgerBarClassName?: string; + burgerButtonClassName?: string; + crossButtonClassName?: string; + crossClassName?: string; + customBurgerIcon?: Element | false; + customCrossIcon?: Element | false; + id?: string; + isOpen?: boolean; + itemListClassName?: string; + menuClassName?: string; + morphShapeClassName?: string; + noOverlay?: boolean; + onStateChange?(): void; + // TODO (Rajab) This can be improved, though I do not know how. From PropTypes: + // styles && styles.outerContainer ? PropTypes.string.isRequired : PropTypes.string + outerContainerId?: string; + overlayClassName?: string; + // TODO (Rajab) This can be improved, though I do not know how. From PropTypes: + // styles && styles.pageWrap ? PropTypes.string.isRequired : PropTypes.string, + pageWrapId?: string; + right?: boolean; + styles?: { + bmBurgerButton: CSSStyleDeclaration; + bmBurgerBars: CSSStyleDeclaration; + bmCrossButton: CSSStyleDeclaration; + bmCross: CSSStyleDeclaration; + bmMenu: CSSStyleDeclaration; + bmMorphShape: CSSStyleDeclaration; + bmItemList: CSSStyleDeclaration; + bmOverlay: CSSStyleDeclaration; + }; + width?: number | string; +} + +// TODO (Rajab) actually I don't want export ReactBurgerMenu, but +// `npm run lint react-burger-menu` error doesn't allow me to do it; +export class ReactBurgerMenu extends React.Component { } + +export class slide extends ReactBurgerMenu { } +export class stack extends ReactBurgerMenu { } +export class elastic extends ReactBurgerMenu { } +export class bubble extends ReactBurgerMenu { } +export class push extends ReactBurgerMenu { } +export class pushRotate extends ReactBurgerMenu { } +export class scaleDown extends ReactBurgerMenu { } +export class scaleRotate extends ReactBurgerMenu { } +export class fallDown extends ReactBurgerMenu { } diff --git a/types/react-burger-menu/react-burger-menu-tests.tsx b/types/react-burger-menu/react-burger-menu-tests.tsx new file mode 100644 index 0000000000..4a9190000b --- /dev/null +++ b/types/react-burger-menu/react-burger-menu-tests.tsx @@ -0,0 +1,21 @@ +import * as React from 'react'; +import { slide as Menu } from 'react-burger-menu'; + +class Example extends React.Component<{}, {}> { + showSettings(event: { + preventDefault(): void; + }) { + event.preventDefault(); + } + + render() { + return ( + + Home + About + Contact + Settings + + ); + } +} diff --git a/types/react-burger-menu/tsconfig.json b/types/react-burger-menu/tsconfig.json new file mode 100644 index 0000000000..19dc806fbe --- /dev/null +++ b/types/react-burger-menu/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "jsx": "react" + }, + "files": [ + "index.d.ts", + "react-burger-menu-tests.tsx" + ] +} diff --git a/types/react-burger-menu/tslint.json b/types/react-burger-menu/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-burger-menu/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/react-lazyload/index.d.ts b/types/react-lazyload/index.d.ts index 2766d998b0..7ec2ae156c 100644 --- a/types/react-lazyload/index.d.ts +++ b/types/react-lazyload/index.d.ts @@ -24,3 +24,5 @@ export default class LazyLoad extends Component { } export function lazyload(option: {}): LazyLoad; + +export function forceCheck(): void; diff --git a/types/react-lazyload/react-lazyload-tests.tsx b/types/react-lazyload/react-lazyload-tests.tsx index 37b928a99c..ce9641dee4 100644 --- a/types/react-lazyload/react-lazyload-tests.tsx +++ b/types/react-lazyload/react-lazyload-tests.tsx @@ -1,5 +1,5 @@ import * as React from "react"; -import LazyLoad from "react-lazyload"; +import LazyLoad, { forceCheck } from "react-lazyload"; interface State { arr: string[]; @@ -14,6 +14,11 @@ class Normal extends React.Component<{}, State> { } this.state = { arr }; } + + componentDidMount() { + forceCheck(); + } + render() { return (
diff --git a/types/react-native-modalbox/index.d.ts b/types/react-native-modalbox/index.d.ts new file mode 100644 index 0000000000..9bd075fbe0 --- /dev/null +++ b/types/react-native-modalbox/index.d.ts @@ -0,0 +1,205 @@ +// Type definitions for react-native-modalbox 1.3 +// Project: https://github.com/maxs15/react-native-modalbox#readme +// Definitions by: Kyle Roach +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import * as React from 'react'; +import { ViewProperties } from 'react-native'; + +export interface ModalProps extends ViewProperties { + /** + * Checks if the modal is open + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + isOpen?: boolean; + + /** + * Checks if the modal is disabled + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + isDisabled?: boolean; + + /** + * If the modal can be closed by pressing on the backdrop + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + backdropPressToClose?: boolean; + + /** + * If the modal can be closed by swiping + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + swipeToClose?: boolean; + + /** + * The threshold to reach in pixels to close the modal + * + * Default is 50 + * + * @type {number} + * @memberof ModalProps + */ + swipeThreshold?: number; + + /** + * The height in pixels of the swipeable area + * + * Default is the Window Height + * + * @type {number} + * @memberof ModalProps + */ + swipeArea?: number; + + /** + * The final position of the modal. + * Accepts top, center or bottom + * + * Default is center + * + * @type {string} + * @memberof ModalProps + */ + position?: 'top' | 'center' | 'bottom' | string; + + /** + * The direction modal enters from + * + * Default is bottom + * + * @type {('top' | 'bottom' | string)} + * @memberof ModalProps + */ + entry?: 'top' | 'bottom' | string; + + /** + * If a backdrop is displayed behind the modal + * + * Default is true + * + * @type {boolean} + * @memberof ModalProps + */ + backdrop?: boolean; + + /** + * Opacity of the backdrop + * + * Default is 0.5 + * + * @type {number} + * @memberof ModalProps + */ + backdropOpacity?: number; + + /** + * Background color of the backdrop + * + * Default is black + * + * @type {string} + * @memberof ModalProps + */ + backdropColor?: string; + + /** + * Add an element in the backdrop (a close button for example) + * + * Default is null + * + * @type {JSX.Element} + * @memberof ModalProps + */ + backdropContent?: React.ReactNode; + + /** + * Duration of the animation + * + * Default is 400ms + * + * @type {number} + * @memberof ModalProps + */ + animationDuration?: number; + + /** + * (Android only) Close modal when receiving back button event + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + backButtonClose?: boolean; + + /** + * If the modal should appear open without animation upon first mount + * + * Default is false + * + * @type {boolean} + * @memberof ModalProps + */ + startOpen?: boolean; + + /** + * Event fired when the modal is closed and the animation is complete + * + * @memberof ModalProps + */ + onClosed?(): void; + + /** + * Event fired when the modal is opened and the animation is complete + * + * @memberof ModalProps + */ + onOpened?(): void; + + /** + * When the state of the swipe to close feature has changed + * (useful to change the content of the modal, display a message for example) + * + * @param {boolean} state + * + * @memberof ModalProps + */ + onClosingState?(state: boolean): void; +} + +export default class Modal extends React.Component { + /** + * Open the modal + * + * @static + * + * @memberof Modal + */ + open(): void; + + /** + * Close the modal + * + * @static + * + * @memberof Modal + */ + close(): void; +} diff --git a/types/react-native-modalbox/react-native-modalbox-tests.tsx b/types/react-native-modalbox/react-native-modalbox-tests.tsx new file mode 100644 index 0000000000..c8ae1785e7 --- /dev/null +++ b/types/react-native-modalbox/react-native-modalbox-tests.tsx @@ -0,0 +1,198 @@ +import * as React from 'react'; +import { + Text, + StyleSheet, + ScrollView, + View, + Dimensions, + Button +} from 'react-native'; +import Modal from 'react-native-modalbox'; + +interface State { + isOpen: boolean; + isDisabled: boolean; + swipeToClose: boolean; + sliderValue: number; +} + +class Example extends React.Component<{}, State> { + modal1: Modal; + modal2: Modal; + modal3: Modal; + modal4: Modal; + modal6: Modal; + + constructor() { + super(); + + this.state = { + isOpen: false, + isDisabled: false, + swipeToClose: true, + sliderValue: 0.3 + }; + } + + onClose() { + console.log('Modal just closed'); + } + + onOpen() { + console.log('Modal just openned'); + } + + onClosingState() { + console.log('the open/close of the swipeToClose just changed'); + } + + renderList() { + const list = []; + + for (let i = 0; i < 50; i++) { + list.push(Elem {i}); + } + + return list; + } + + render() { + const BContent = ( +