From 2b7681ee6c02e7442c6b6c2916ccb71824923b8c Mon Sep 17 00:00:00 2001 From: martin-badin Date: Thu, 16 Apr 2020 01:22:29 +0200 Subject: [PATCH] [@types/jquery] Improve type for find function (#43857) --- types/jquery/JQuery.d.ts | 4 +++- types/jquery/index.d.ts | 1 + types/jquery/jquery-tests.ts | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/types/jquery/JQuery.d.ts b/types/jquery/JQuery.d.ts index ed0147a89f..1d317a94b2 100644 --- a/types/jquery/JQuery.d.ts +++ b/types/jquery/JQuery.d.ts @@ -4133,7 +4133,9 @@ $( "p" ) ``` */ - find(selector_element: JQuery.Selector | Element | JQuery): this; + find(selector_element: K | JQuery): JQuery; + find(selector_element: K | JQuery): JQuery; + find(selector_element: JQuery.Selector | E | JQuery): JQuery; /** * 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. diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 2d4171320b..9b3207bc65 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -22,6 +22,7 @@ // Dick van den Brink // Thomas Schulz // Terry Mun +// Martin Badin // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 9391596f37..10ddf26f6a 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -5849,14 +5849,26 @@ function JQuery() { } function find() { - // $ExpectType JQuery + // $ExpectType JQuery $('p').find('span'); + // $ExpectType JQuery + $('p').find('.class-name'); + // $ExpectType JQuery $('p').find(new HTMLElement()); + // $ExpectType JQuery + $('p').find(new HTMLSpanElement()); + // $ExpectType JQuery $('p').find($('span')); + + // $ExpectType JQuery + $('p').find($('.class-name')); + + // $ExpectType JQuery + $('p').find($('.class-name')); } function addBack() { @@ -5897,11 +5909,17 @@ function JQuery() { function first() { // $ExpectType JQuery $('p').first(); + + // $ExpectType JQuery + $('p').find('span').first(); } function last() { // $ExpectType JQuery $('p').last(); + + // $ExpectType JQuery + $('p').find('span').first(); } function offsetParent() {