[jquery] Clean up misc-related methods on JQuery.

Add tests for misc-related methods on JQuery.
This commit is contained in:
Leonard Thieu
2017-06-21 20:30:39 -04:00
parent 798ce5ea69
commit 40e4a08d66
2 changed files with 78 additions and 2 deletions
+2 -2
View File
@@ -620,7 +620,7 @@ interface JQuery<TElement extends Node = HTMLElement> {
* @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<TElement extends Node = HTMLElement> {
* @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.
*
+76
View File
@@ -3387,6 +3387,82 @@ function JQuery() {
// $ExpectType JQuery<HTMLElement>
$('p').slice(0);
}
function pushStack() {
// $ExpectType JQuery<HTMLElement>
$('p').pushStack([new HTMLElement()], 'name', ['arg']);
// $ExpectType JQuery<HTMLElement>
$('p').pushStack([new HTMLElement()]);
}
}
function misc() {
function serialize() {
// $ExpectType string
$('p').serialize();
}
function serializeArray() {
// $ExpectType NameValuePair[]
$('p').serializeArray();
}
function each() {
// $ExpectType JQuery<HTMLElement>
$('p').each(function(index, element) {
// $ExpectType HTMLElement
this;
// $ExpectType number
index;
// $ExpectType HTMLElement
element;
});
// $ExpectType JQuery<HTMLElement>
$('p').each(function(index, element) {
// $ExpectType HTMLElement
this;
// $ExpectType number
index;
// $ExpectType HTMLElement
element;
return false;
});
}
function extend() {
// $ExpectType JQuery<HTMLElement>
$.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();
}
}
}