[@types/jquery] Improve type for find function (#43857)

This commit is contained in:
martin-badin 2020-04-16 01:22:29 +02:00 committed by GitHub
parent 1186f63e5f
commit 2b7681ee6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -4133,7 +4133,9 @@ $( "p" )
</html>
```
*/
find(selector_element: JQuery.Selector | Element | JQuery): this;
find<K extends keyof HTMLElementTagNameMap>(selector_element: K | JQuery<K>): JQuery<HTMLElementTagNameMap[K]>;
find<K extends keyof SVGElementTagNameMap>(selector_element: K | JQuery<K>): JQuery<SVGElementTagNameMap[K]>;
find<E extends HTMLElement>(selector_element: JQuery.Selector | E | JQuery<E>): JQuery<E>;
/**
* Stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements.
* @param queue The name of the queue in which to stop animations.

View File

@ -22,6 +22,7 @@
// Dick van den Brink <https://github.com/DickvdBrink>
// Thomas Schulz <https://github.com/King2500>
// Terry Mun <https://github.com/terrymun>
// Martin Badin <https://github.com/martin-badin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

View File

@ -5849,14 +5849,26 @@ function JQuery() {
}
function find() {
// $ExpectType JQuery<HTMLElement>
// $ExpectType JQuery<HTMLSpanElement>
$('p').find('span');
// $ExpectType JQuery<HTMLElement>
$('p').find('.class-name');
// $ExpectType JQuery<HTMLElement>
$('p').find(new HTMLElement());
// $ExpectType JQuery<HTMLSpanElement>
$('p').find(new HTMLSpanElement());
// $ExpectType JQuery<HTMLElement>
$('p').find($('span'));
// $ExpectType JQuery<HTMLSpanElement>
$('p').find($<HTMLSpanElement>('.class-name'));
// $ExpectType JQuery<HTMLSpanElement>
$('p').find<HTMLSpanElement>($('.class-name'));
}
function addBack() {
@ -5897,11 +5909,17 @@ function JQuery() {
function first() {
// $ExpectType JQuery<HTMLElement>
$('p').first();
// $ExpectType JQuery<HTMLSpanElement>
$('p').find('span').first();
}
function last() {
// $ExpectType JQuery<HTMLElement>
$('p').last();
// $ExpectType JQuery<HTMLSpanElement>
$('p').find('span').first();
}
function offsetParent() {