diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 0e007b689e..60583af1bc 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -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. * @@ -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. * diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index a5b668a9ba..2536144845 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -3387,6 +3387,82 @@ function JQuery() { // $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(); + } } }