[angular] Add index signature to JQLite. (#18767)

This commit is contained in:
Leonard Thieu
2017-08-14 14:28:41 -04:00
committed by Mohamed Hegazy
parent a91ea3e7fa
commit 351589d38d
5 changed files with 100 additions and 84 deletions

View File

@@ -974,7 +974,7 @@ declare namespace angular {
// DocumentService
// see http://docs.angularjs.org/api/ng.$document
///////////////////////////////////////////////////////////////////////////
interface IDocumentService extends JQuery {
interface IDocumentService extends JQLite {
// Must return intersection type for index signature compatibility with JQuery
[index: number]: HTMLElement & Document;
}
@@ -991,7 +991,7 @@ declare namespace angular {
// RootElementService
// see http://docs.angularjs.org/api/ng.$rootElement
///////////////////////////////////////////////////////////////////////////
interface IRootElementService extends JQuery {}
interface IRootElementService extends JQLite {}
interface IQResolveReject<T> {
(): void;
@@ -1302,12 +1302,12 @@ declare namespace angular {
interface ICloneAttachFunction {
// Let's hint but not force cloneAttachFn's signature
(clonedElement?: JQuery, scope?: IScope): any;
(clonedElement?: JQLite, scope?: IScope): any;
}
// This corresponds to the "publicLinkFn" returned by $compile.
interface ITemplateLinkingFunction {
(scope: IScope, cloneAttachFn?: ICloneAttachFunction, options?: ITemplateLinkingFunctionOptions): JQuery;
(scope: IScope, cloneAttachFn?: ICloneAttachFunction, options?: ITemplateLinkingFunctionOptions): JQLite;
}
interface ITemplateLinkingFunctionOptions {
@@ -1325,9 +1325,9 @@ declare namespace angular {
*/
interface ITranscludeFunction {
// If the scope is provided, then the cloneAttachFn must be as well.
(scope: IScope, cloneAttachFn: ICloneAttachFunction, futureParentElement?: JQuery, slotName?: string): JQuery;
(scope: IScope, cloneAttachFn: ICloneAttachFunction, futureParentElement?: JQuery, slotName?: string): JQLite;
// If one argument is provided, then it's assumed to be the cloneAttachFn.
(cloneAttachFn?: ICloneAttachFunction, futureParentElement?: JQuery, slotName?: string): JQuery;
(cloneAttachFn?: ICloneAttachFunction, futureParentElement?: JQuery, slotName?: string): JQLite;
/**
* Returns true if the specified slot contains content (i.e. one or more DOM nodes)
@@ -1962,7 +1962,7 @@ declare namespace angular {
interface IDirectiveLinkFn {
(
scope: IScope,
instanceElement: JQuery,
instanceElement: JQLite,
instanceAttributes: IAttributes,
controller?: IController | IController[] | {[key: string]: IController},
transclude?: ITranscludeFunction
@@ -1976,7 +1976,7 @@ declare namespace angular {
interface IDirectiveCompileFn {
(
templateElement: JQuery,
templateElement: JQLite,
templateAttributes: IAttributes,
/**
* @deprecated
@@ -2008,9 +2008,9 @@ declare namespace angular {
require?: string | string[] | {[controller: string]: string};
restrict?: string;
scope?: boolean | {[boundProperty: string]: string};
template?: string | ((tElement: JQuery, tAttrs: IAttributes) => string);
template?: string | ((tElement: JQLite, tAttrs: IAttributes) => string);
templateNamespace?: string;
templateUrl?: string | ((tElement: JQuery, tAttrs: IAttributes) => string);
templateUrl?: string | ((tElement: JQLite, tAttrs: IAttributes) => string);
terminal?: boolean;
transclude?: boolean | 'element' | {[slot: string]: string};
}
@@ -2023,7 +2023,7 @@ declare namespace angular {
* See: http://docs.angularjs.org/api/angular.element
*/
interface IAugmentedJQueryStatic extends JQueryStatic {}
interface IAugmentedJQuery extends JQuery {}
interface IAugmentedJQuery extends JQLite {}
/**
* Same as IController. Keeping it for compatibility with older versions of these type definitions.

View File

@@ -25,6 +25,10 @@
// Definitions copied from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/0480c5ec87fab41aa23047a02b27f0ea71aaf975/types/jquery/v2/index.d.ts
interface JQLite extends JQuery {
[index: number]: HTMLElement;
}
interface JQuery {
/**
* Adds the specified class(es) to each of the set of matched elements.
@@ -32,7 +36,7 @@ interface JQuery {
* @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;
addClass(className: string): this;
/**
* Insert content, specified by the parameter, after each element in the set of matched elements.
@@ -41,14 +45,14 @@ interface JQuery {
* @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;
after(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): this;
/**
* 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;
after(func: (index: number, html: string) => string | Element | JQuery): this;
/**
* Insert content, specified by the parameter, to the end of each element in the set of matched elements.
@@ -57,14 +61,14 @@ interface JQuery {
* @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;
append(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): this;
/**
* 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;
append(func: (index: number, html: string) => string | Element | JQuery): this;
/**
* Get the value of an attribute for the first element in the set of matched elements.
@@ -80,14 +84,14 @@ interface JQuery {
* @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;
attr(attributeName: string, value: string | number | null): this;
/**
* 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;
attr(attributes: Object): this;
/**
* Attach a handler to an event for the elements.
@@ -96,7 +100,7 @@ interface JQuery {
* @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;
bind(eventType: string, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Attach a handler to an event for the elements.
*
@@ -104,21 +108,21 @@ interface JQuery {
* @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;
bind(eventType: string, preventBubble: boolean): this;
/**
* 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;
bind(events: any): this;
/**
* 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;
children(): this;
/**
* Create a deep copy of the set of matched elements.
@@ -127,13 +131,13 @@ interface JQuery {
* @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;
clone(withDataAndEvents?: boolean, deepWithDataAndEvents?: boolean): 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/}
*/
contents(): JQuery;
contents(): this;
/**
* Get the value of style properties for the first element in the set of matched elements.
@@ -157,7 +161,7 @@ interface JQuery {
* @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;
css(propertyName: string, value: string | number): this;
/**
* Set one or more CSS properties for the set of matched elements.
*
@@ -165,14 +169,14 @@ interface JQuery {
* @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;
css(propertyName: string, value: (index: number, value: string) => string | number): this;
/**
* 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: JQLiteCssProperties): JQuery;
css(properties: JQLiteCssProperties): this;
/**
* Store arbitrary data associated with the matched elements.
@@ -181,7 +185,7 @@ interface JQuery {
* @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;
data(key: string, value: any): this;
/**
* 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.
*
@@ -195,7 +199,7 @@ interface JQuery {
* @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;
data(obj: { [key: string]: any; }): this;
/**
* 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}
@@ -208,13 +212,13 @@ interface JQuery {
* @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;
detach(selector?: string): this;
/**
* Remove all child nodes of the set of matched elements from the DOM.
* @see {@link https://api.jquery.com/empty/}
*/
empty(): JQuery;
empty(): this;
/**
* Reduce the set of matched elements to the one at the specified index.
@@ -222,7 +226,7 @@ interface JQuery {
* @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;
eq(index: number): this;
/**
* Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.
@@ -230,9 +234,9 @@ interface JQuery {
* @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;
find(selector: string): this;
find(element: any): this;
find(obj: JQuery): this;
/**
* Determine whether any of the matched elements are assigned the given class.
@@ -253,21 +257,21 @@ interface JQuery {
* @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;
html(htmlString: string): this;
/**
* 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;
html(func: (index: number, oldhtml: string) => string): this;
/**
* 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;
next(): this;
/**
* Attach an event handler function for one or more events to the selected elements.
@@ -276,7 +280,7 @@ interface JQuery {
* @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;
on(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): this;
/**
* Attach an event handler function for one or more events to the selected elements.
*
@@ -285,7 +289,7 @@ interface JQuery {
* @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;
on(events: string, data: any, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): this;
/**
* Attach an event handler function for one or more events to the selected elements.
*
@@ -294,7 +298,7 @@ interface JQuery {
* @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;
on(events: string, selector: string, handler: (eventObject: JQueryEventObject, ...eventData: any[]) => any): this;
/**
* Attach an event handler function for one or more events to the selected elements.
*
@@ -304,7 +308,7 @@ interface JQuery {
* @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;
on(events: string, selector: string, data: any, handler: (eventObject: JQueryEventObject, ...eventData: any[]) => any): this;
/**
* Attach an event handler function for one or more events to the selected elements.
*
@@ -313,7 +317,7 @@ interface JQuery {
* @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;
on(events: { [key: string]: (eventObject: JQueryEventObject, ...args: any[]) => any; }, selector?: string, data?: any): this;
/**
* Attach an event handler function for one or more events to the selected elements.
*
@@ -321,13 +325,13 @@ interface JQuery {
* @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;
on(events: { [key: string]: (eventObject: JQueryEventObject, ...args: any[]) => any; }, data?: any): this;
/**
* Remove an event handler.
* @see {@link https://api.jquery.com/off/#off}
*/
off(): JQuery;
off(): this;
/**
* Remove an event handler.
*
@@ -336,7 +340,7 @@ interface JQuery {
* @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;
off(events: string, selector?: string, handler?: (eventObject: JQueryEventObject) => any): this;
/**
* Remove an event handler.
*
@@ -344,7 +348,7 @@ interface JQuery {
* @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;
off(events: string, handler: (eventObject: JQueryEventObject, ...args: any[]) => any): this;
/**
* Remove an event handler.
*
@@ -352,7 +356,7 @@ interface JQuery {
* @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;
off(events: string, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Remove an event handler.
*
@@ -360,7 +364,7 @@ interface JQuery {
* @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;
off(events: { [key: string]: any; }, selector?: string): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
@@ -369,7 +373,7 @@ interface JQuery {
* @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;
one(events: string, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
*
@@ -378,7 +382,7 @@ interface JQuery {
* @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;
one(events: string, data: Object, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
*
@@ -387,7 +391,7 @@ interface JQuery {
* @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;
one(events: string, selector: string, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
*
@@ -397,7 +401,7 @@ interface JQuery {
* @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;
one(events: string, selector: string, data: any, handler: (eventObject: JQueryEventObject) => any): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
*
@@ -406,7 +410,7 @@ interface JQuery {
* @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;
one(events: { [key: string]: any; }, selector?: string, data?: any): this;
/**
* Attach a handler to an event for the elements. The handler is executed at most once per element per event type.
*
@@ -414,14 +418,14 @@ interface JQuery {
* @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;
one(events: { [key: string]: any; }, data?: any): this;
/**
* 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;
parent(): this;
/**
* Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.
@@ -430,14 +434,14 @@ interface JQuery {
* @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;
prepend(content1: JQuery | any[] | Element | DocumentFragment | Text | string, ...content2: any[]): this;
/**
* 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;
prepend(func: (index: number, html: string) => string | Element | JQuery): this;
/**
* Get the value of a property for the first element in the set of matched elements.
@@ -453,14 +457,14 @@ interface JQuery {
* @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;
prop(propertyName: string, value: string | number | boolean): this;
/**
* 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;
prop(properties: Object): this;
/**
* Set one or more properties for the set of matched elements.
*
@@ -468,7 +472,7 @@ interface JQuery {
* @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;
prop(propertyName: string, func: (index: number, oldPropertyValue: any) => any): this;
/**
* Specify a function to execute when the DOM is fully loaded.
@@ -476,7 +480,7 @@ interface JQuery {
* @param handler A function to execute after the DOM is ready.
* @see {@link https://api.jquery.com/ready/}
*/
ready(handler: (jQueryAlias?: JQueryStatic) => any): JQuery;
ready(handler: (jQueryAlias?: JQueryStatic) => any): this;
/**
* Remove the set of matched elements from the DOM.
@@ -484,7 +488,7 @@ interface JQuery {
* @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(selector?: string): this;
/**
* Remove an attribute from each element in the set of matched elements.
@@ -492,7 +496,7 @@ interface JQuery {
* @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;
removeAttr(attributeName: string): this;
/**
* Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
@@ -500,7 +504,7 @@ interface JQuery {
* @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;
removeClass(className?: string): this;
/**
* Remove a previously-stored piece of data.
@@ -508,19 +512,19 @@ interface JQuery {
* @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;
removeData(name: string): this;
/**
* 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;
removeData(list: string[]): this;
/**
* Remove all previously-stored piece of data.
* @see {@link https://api.jquery.com/removeData/}
*/
removeData(): JQuery;
removeData(): this;
/**
* Replace each element in the set of matched elements with the provided new content and return the set of elements that was removed.
@@ -528,14 +532,14 @@ interface JQuery {
* @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;
replaceWith(newContent: JQuery | any[] | Element | Text | string): this;
/**
* 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;
replaceWith(func: () => Element | JQuery): this;
/**
* Get the combined text contents of each element in the set of matched elements, including their descendants.
@@ -548,14 +552,14 @@ interface JQuery {
* @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;
text(text: string | number | boolean): this;
/**
* 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;
text(func: (index: number, text: string) => string): this;
/**
* 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.
@@ -564,14 +568,14 @@ interface JQuery {
* @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;
toggleClass(className: string, swtch?: boolean): this;
/**
* 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;
toggleClass(swtch?: boolean): this;
/**
* Execute all handlers attached to an element for an event.
@@ -597,7 +601,7 @@ interface JQuery {
* @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;
unbind(eventType?: string, handler?: (eventObject: JQueryEventObject) => any): this;
/**
* Remove a previously-attached event handler from the elements.
*
@@ -605,14 +609,14 @@ interface JQuery {
* @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;
unbind(eventType: string, fls: boolean): this;
/**
* 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;
unbind(evt: any): this;
/**
* Get the current value of the first element in the set of matched elements.
@@ -625,14 +629,14 @@ interface JQuery {
* @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;
val(value: string | string[] | number): this;
/**
* 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;
val(func: (index: number, value: string) => string): this;
/**
* Wrap an HTML structure around each element in the set of matched elements.
@@ -640,14 +644,14 @@ interface JQuery {
* @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(wrappingElement: JQuery | Element | string): this;
/**
* 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;
wrap(func: (index: number) => string | JQuery): this;
// Undocumented
length: number;
@@ -661,13 +665,13 @@ interface JQuery {
scope<T extends ng.IScope>(): T;
isolateScope<T extends ng.IScope>(): T;
inheritedData(key: string, value: any): JQuery;
inheritedData(obj: { [key: string]: any; }): JQuery;
inheritedData(key: string, value: any): this;
inheritedData(obj: { [key: string]: any; }): this;
inheritedData(key?: string): any;
}
interface JQueryStatic {
(element: string | Element | Document | JQuery | ArrayLike<Element>): JQuery;
(element: string | Element | Document | JQuery | ArrayLike<Element>): JQLite;
}
/**

View File

@@ -0,0 +1,7 @@
import * as angular from 'angular';
function JQLite() {
function indexSignature() {
angular.element('p')[0]; // $ExpectType HTMLElement
}
}

View File

@@ -2,6 +2,10 @@ import $ = require('jquery');
import * as angular from 'angular';
function JQuery() {
function indexSignature() {
$('p')[0]; // $ExpectType HTMLElement
}
function addClass() {
// $ExpectType JQuery<HTMLElement>
$('p').addClass('className');

View File

@@ -3,6 +3,7 @@
"index.d.ts",
"jqlite.d.ts",
"angular-tests.ts",
"test/jqlite-tests.ts",
"test/jquery3-merging-tests.ts"
],
"compilerOptions": {