From 798ce5ea6904f00eee62aaf16acff73b125d3f4f Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Wed, 21 Jun 2017 19:14:53 -0400 Subject: [PATCH] [jquery] Clean up manipulation-, queue-, and traversing-related methods on JQuery. Add tests for manipulation-, queue-, and traversing-related methods on JQuery. --- types/jquery/index.d.ts | 30 +- types/jquery/jquery-tests.ts | 985 +++++++++++++++++++++++++++++ types/jquery/test/example-tests.ts | 2 +- 3 files changed, 1001 insertions(+), 16 deletions(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index d9d5a5bdc6..0e007b689e 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -62,7 +62,7 @@ interface JQuery { * @see {@link https://api.jquery.com/add/} * @since 1.4 */ - add(selector: JQuery.Selector, context: Element): JQuery; + add(selector: JQuery.Selector, context: Element): this; /** * Create a new jQuery object with elements added to the set of matched elements. * @@ -74,7 +74,7 @@ interface JQuery { * @since 1.0 * @since 1.3.2 */ - add(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery.htmlString | JQuery): JQuery; + add(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery.htmlString | JQuery): this; /** * Add the previous set of elements on the stack to the current set, optionally filtered by a selector. * @@ -426,14 +426,14 @@ interface JQuery { * @since 1.3 * @since 1.6 */ - closest(selector: JQuery.Selector | JQuery | Element): this; + closest(selector: JQuery.Selector | Element | JQuery): 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/} * @since 1.2 */ - contents(): this; + contents(): JQuery; /** * Bind an event handler to the "contextmenu" JavaScript event, or trigger that event on an element. * @@ -653,7 +653,7 @@ interface JQuery { * @see {@link https://api.jquery.com/jQuery.fn.extend/} * @since 1.0 */ - extend(obj: object): JQuery; + extend(obj: object): this; /** * Display the matched elements by fading them to opaque. * @@ -796,7 +796,7 @@ interface JQuery { * @since 1.0 * @since 1.6 */ - find(selector: JQuery.Selector | Element | JQuery): JQuery; + find(selector: JQuery.Selector | Element | JQuery): this; /** * Stop the currently-running animation, remove all queued animations, and complete all animations for * the matched elements. @@ -1058,7 +1058,7 @@ interface JQuery { * @since 1.0 * @since 1.6 */ - is(selector: JQuery.Selector | ((this: TElement, index: number, element: TElement) => boolean) | JQuery | Element | Element[]): boolean; + is(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery | ((this: TElement, index: number, element: TElement) => boolean)): boolean; /** * Bind an event handler to the "keydown" JavaScript event, or trigger that event on an element. * @@ -1148,7 +1148,7 @@ interface JQuery { * @see {@link https://api.jquery.com/map/} * @since 1.2 */ - map(callback: (this: TElement, index: number, domElement: TElement) => any | any[] | null | undefined): JQuery; + map(callback: (this: TElement, index: number, domElement: TElement) => any | any[] | null | undefined): this; /** * Bind an event handler to the "mousedown" JavaScript event, or trigger that event on an element. * @@ -1309,7 +1309,7 @@ interface JQuery { * @since 1.0 * @since 1.4 */ - not(selector: JQuery.Selector | JQuery.TypeOrArray | ((this: TElement, index: number, element: TElement) => boolean) | JQuery): this; + not(selector: JQuery.Selector | JQuery.TypeOrArray | JQuery | ((this: TElement, index: number, element: TElement) => boolean)): this; /** * Remove an event handler. * @@ -1688,7 +1688,7 @@ interface JQuery { * @see {@link https://api.jquery.com/promise/} * @since 1.6 */ - promise(type: string, target: T): T & JQuery.Promise; + promise(type: string, target: T): T & JQuery.Promise; /** * Return a Promise object to observe when all actions of a certain type bound to the collection, * queued or not, have finished. @@ -1697,7 +1697,7 @@ interface JQuery { * @see {@link https://api.jquery.com/promise/} * @since 1.6 */ - promise(target: T): T & JQuery.Promise; + promise(target: T): T & JQuery.Promise; /** * Return a Promise object to observe when all actions of a certain type bound to the collection, * queued or not, have finished. @@ -1751,7 +1751,7 @@ interface JQuery { * @see {@link https://api.jquery.com/pushStack/} * @since 1.3 */ - pushStack(elements: ArrayLike, name: string, args: any[]): JQuery; + pushStack(elements: ArrayLike, name: string, args: any[]): this; /** * Add a collection of DOM elements onto the jQuery stack. * @@ -1759,7 +1759,7 @@ interface JQuery { * @see {@link https://api.jquery.com/pushStack/} * @since 1.0 */ - pushStack(elements: ArrayLike): JQuery; + pushStack(elements: ArrayLike): this; /** * Manipulate the queue of functions to be executed, once for each matched element. * @@ -1858,7 +1858,7 @@ interface JQuery { * @since 1.2 * @since 1.4 */ - replaceWith(newContent: JQuery.htmlString | JQuery.TypeOrArray | JQuery | ((this: TElement) => any)): JQuery; + replaceWith(newContent: JQuery.htmlString | JQuery | JQuery.TypeOrArray | ((this: TElement) => any)): this; /** * Bind an event handler to the "resize" JavaScript event, or trigger that event on an element. * @@ -2388,7 +2388,7 @@ interface JQuery { * @since 1.2 * @since 1.4 */ - wrapInner(wrappingElement: JQuery.Selector | JQuery.htmlString | Element | JQuery | ((this: TElement, index: number) => string | Element | JQuery)): this; + wrapInner(wrappingElement: JQuery.Selector | JQuery.htmlString | Element | JQuery | ((this: TElement, index: number) => string | JQuery | Element)): this; } interface JQuery extends ArrayLike, Iterable { } diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index c31352cb02..a5b668a9ba 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1277,7 +1277,9 @@ function JQuery() { // $ExpectType JQuery $('p').show(); } + } + function queue() { function clearQueue() { // $ExpectType JQuery $('p').clearQueue('myQueue'); @@ -1379,6 +1381,17 @@ function JQuery() { // $ExpectType JQuery $('p').stop(true); } + + function promise() { + // $ExpectType { description: string; } & Promise, any, any> + $('p').promise('myQueue', { description: 'desc' }); + + // $ExpectType { description: string; } & Promise, any, any> + $('p').promise({ description: 'desc' }); + + // $ExpectType Promise, any, any> + $('p').promise(); + } } function events() { @@ -2403,6 +2416,978 @@ function JQuery() { }); } } + + function manipulation() { + function after() { + // $ExpectType JQuery + $('p').after('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').after(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function append() { + // $ExpectType JQuery + $('p').append('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').append(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function before() { + // $ExpectType JQuery + $('p').before('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').before(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function prepend() { + // $ExpectType JQuery + $('p').prepend('

', new Element(), new Text(), $('p'), [new Element(), new Text()]); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return '

'; + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Element(); + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return new Text(); + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return [new Element(), new Text()]; + }); + + // $ExpectType JQuery + $('p').prepend(function(index, html) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + html; + + return $('p'); + }); + } + + function appendTo() { + // $ExpectType JQuery + $('span').appendTo('p'); + + // $ExpectType JQuery + $('span').appendTo('

'); + + // $ExpectType JQuery + $('span').appendTo(new HTMLElement()); + + // $ExpectType JQuery + $('span').appendTo([new HTMLElement()]); + + // $ExpectType JQuery + $('span').appendTo($('p')); + } + + function insertAfter() { + // $ExpectType JQuery + $('span').insertAfter('p'); + + // $ExpectType JQuery + $('span').insertAfter('

'); + + // $ExpectType JQuery + $('span').insertAfter(new HTMLElement()); + + // $ExpectType JQuery + $('span').insertAfter([new HTMLElement()]); + + // $ExpectType JQuery + $('span').insertAfter($('p')); + } + + function insertBefore() { + // $ExpectType JQuery + $('span').insertBefore('p'); + + // $ExpectType JQuery + $('span').insertBefore('

'); + + // $ExpectType JQuery + $('span').insertBefore(new HTMLElement()); + + // $ExpectType JQuery + $('span').insertBefore([new HTMLElement()]); + + // $ExpectType JQuery + $('span').insertBefore($('p')); + } + + function prependTo() { + // $ExpectType JQuery + $('span').prependTo('p'); + + // $ExpectType JQuery + $('span').prependTo('

'); + + // $ExpectType JQuery + $('span').prependTo(new HTMLElement()); + + // $ExpectType JQuery + $('span').prependTo([new HTMLElement()]); + + // $ExpectType JQuery + $('span').prependTo($('p')); + } + + function clone() { + // $ExpectType JQuery + $('p').clone(true, true); + + // $ExpectType JQuery + $('p').clone(true); + + // $ExpectType JQuery + $('p').clone(); + } + + function detach() { + // $ExpectType JQuery + $('p').detach('span'); + + // $ExpectType JQuery + $('p').detach(); + } + + function empty() { + // $ExpectType JQuery + $('p').empty(); + } + + function remove() { + // $ExpectType JQuery + $('p').remove('span'); + + // $ExpectType JQuery + $('p').remove(); + } + + function replaceAll() { + // $ExpectType JQuery + $('p').replaceAll('span'); + + // $ExpectType JQuery + $('p').replaceAll($('span')); + + // $ExpectType JQuery + $('p').replaceAll(new HTMLElement()); + + // $ExpectType JQuery + $('p').replaceAll([new HTMLElement()]); + } + + function replaceWith() { + // $ExpectType JQuery + $('p').replaceWith(''); + + // $ExpectType JQuery + $('p').replaceWith($('span')); + + // $ExpectType JQuery + $('p').replaceWith(new HTMLElement()); + + // $ExpectType JQuery + $('p').replaceWith([new HTMLElement()]); + + // $ExpectType JQuery + $('p').replaceWith(function() { + // $ExpectType HTMLElement + this; + + return this; + }); + } + + function unwrap() { + // $ExpectType JQuery + $('p').unwrap('span'); + + // $ExpectType JQuery + $('p').unwrap(); + } + + function wrap() { + // $ExpectType JQuery + $('p').wrap('span'); + + // $ExpectType JQuery + $('p').wrap(''); + + // $ExpectType JQuery + $('p').wrap(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrap($('span')); + + // $ExpectType JQuery + $('p').wrap(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrap(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return $('span'); + }); + } + + function wrapAll() { + // $ExpectType JQuery + $('p').wrapAll('span'); + + // $ExpectType JQuery + $('p').wrapAll(''); + + // $ExpectType JQuery + $('p').wrapAll(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrapAll($('span')); + + // $ExpectType JQuery + $('p').wrapAll(function() { + // $ExpectType HTMLElement + this; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrapAll(function() { + // $ExpectType HTMLElement + this; + + return $('span'); + }); + } + + function wrapInner() { + // $ExpectType JQuery + $('p').wrapInner('span'); + + // $ExpectType JQuery + $('p').wrapInner(''); + + // $ExpectType JQuery + $('p').wrapInner(new HTMLElement()); + + // $ExpectType JQuery + $('p').wrapInner($('span')); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return ''; + }); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return $('span'); + }); + + // $ExpectType JQuery + $('p').wrapInner(function(index) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + + return new HTMLElement(); + }); + } + + function html() { + // $ExpectType JQuery + $('p').html(''); + + // $ExpectType JQuery + $('p').html(function(index, oldhtml) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + oldhtml; + + return oldhtml; + }); + + // $ExpectType string + $('p').html(); + } + + function text() { + // $ExpectType JQuery + $('p').text('myText'); + + // $ExpectType JQuery + $('p').text(4); + + // $ExpectType JQuery + $('p').text(true); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return 'myText'; + }); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return 3; + }); + + // $ExpectType JQuery + $('p').text(function(index, text) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + text; + + return false; + }); + + // $ExpectType string + $('p').text(); + } + + function val() { + // $ExpectType JQuery + $('p').val('myVal'); + + // $ExpectType JQuery + $('p').val(5); + + // $ExpectType JQuery + $('p').val(['myVal']); + + // $ExpectType JQuery + $('p').val(function(index, value) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType string + value; + + return 'myVal'; + }); + + // $ExpectType string | number | string[] | undefined + $('p').val(); + } + } + + function traversing() { + function add() { + // $ExpectType JQuery + $('p').add('span', new HTMLElement()); + + // $ExpectType JQuery + $('p').add('span'); + + // $ExpectType JQuery + $('p').add(new HTMLElement()); + + // $ExpectType JQuery + $('p').add([new HTMLElement()]); + + // $ExpectType JQuery + $('p').add(''); + + // $ExpectType JQuery + $('p').add($('span')); + } + + function closest() { + // $ExpectType JQuery + $('p').closest('span', new HTMLElement()); + + // $ExpectType JQuery + $('p').closest('span'); + + // $ExpectType JQuery + $('p').closest(new HTMLElement()); + + // $ExpectType JQuery + $('p').closest($('span')); + } + + function find() { + // $ExpectType JQuery + $('p').find('span'); + + // $ExpectType JQuery + $('p').find(new HTMLElement()); + + // $ExpectType JQuery + $('p').find($('span')); + } + + function addBack() { + // $ExpectType JQuery + $('p').addBack('span'); + + // $ExpectType JQuery + $('p').addBack(); + } + + function children() { + // $ExpectType JQuery + $('p').children('span'); + + // $ExpectType JQuery + $('p').children(); + } + + function siblings() { + // $ExpectType JQuery + $('p').siblings('span'); + + // $ExpectType JQuery + $('p').siblings(); + } + + function contents() { + // $ExpectType JQuery + $('p').contents(); + } + + function end() { + // $ExpectType JQuery + $('p').end(); + } + + function first() { + // $ExpectType JQuery + $('p').first(); + } + + function last() { + // $ExpectType JQuery + $('p').last(); + } + + function offsetParent() { + // $ExpectType JQuery + $('p').offsetParent(); + } + + function filter() { + // $ExpectType JQuery + $('p').filter('span'); + + // $ExpectType JQuery + $('p').filter(new HTMLElement()); + + // $ExpectType JQuery + $('p').filter([new HTMLElement()]); + + // $ExpectType JQuery + $('p').filter($('span')); + + // $ExpectType JQuery + $('p').filter(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function not() { + // $ExpectType JQuery + $('p').not('span'); + + // $ExpectType JQuery + $('p').not(new HTMLElement()); + + // $ExpectType JQuery + $('p').not([new HTMLElement()]); + + // $ExpectType JQuery + $('p').not($('span')); + + // $ExpectType JQuery + $('p').not(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function is() { + // $ExpectType boolean + $('p').is('span'); + + // $ExpectType boolean + $('p').is(new HTMLElement()); + + // $ExpectType boolean + $('p').is([new HTMLElement()]); + + // $ExpectType boolean + $('p').is($('span')); + + // $ExpectType boolean + $('p').is(function(index, element) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + element; + + return false; + }); + } + + function next() { + // $ExpectType JQuery + $('p').next('span'); + + // $ExpectType JQuery + $('p').next(); + } + + function nextAll() { + // $ExpectType JQuery + $('p').nextAll('span'); + + // $ExpectType JQuery + $('p').nextAll(); + } + + function nextUntil() { + // $ExpectType JQuery + $('p').nextUntil('span', 'span'); + + // $ExpectType JQuery + $('p').nextUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').nextUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').nextUntil('span'); + + // $ExpectType JQuery + $('p').nextUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').nextUntil($('span')); + + // $ExpectType JQuery + $('p').nextUntil(); + } + + function prev() { + // $ExpectType JQuery + $('p').prev('span'); + + // $ExpectType JQuery + $('p').prev(); + } + + function prevAll() { + // $ExpectType JQuery + $('p').prevAll('span'); + + // $ExpectType JQuery + $('p').prevAll(); + } + + function prevUntil() { + // $ExpectType JQuery + $('p').prevUntil('span', 'span'); + + // $ExpectType JQuery + $('p').prevUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').prevUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').prevUntil('span'); + + // $ExpectType JQuery + $('p').prevUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').prevUntil($('span')); + + // $ExpectType JQuery + $('p').prevUntil(); + } + + function parent() { + // $ExpectType JQuery + $('p').parent('span'); + + // $ExpectType JQuery + $('p').parent(); + } + + function parents() { + // $ExpectType JQuery + $('p').parents('span'); + + // $ExpectType JQuery + $('p').parents(); + } + + function parentsUntil() { + // $ExpectType JQuery + $('p').parentsUntil('span', 'span'); + + // $ExpectType JQuery + $('p').parentsUntil(new HTMLElement(), 'span'); + + // $ExpectType JQuery + $('p').parentsUntil($('span'), 'span'); + + // $ExpectType JQuery + $('p').parentsUntil('span'); + + // $ExpectType JQuery + $('p').parentsUntil(new HTMLElement()); + + // $ExpectType JQuery + $('p').parentsUntil($('span')); + + // $ExpectType JQuery + $('p').parentsUntil(); + } + + function eq() { + // $ExpectType JQuery + $('p').eq(0); + } + + function has() { + // $ExpectType JQuery + $('p').has('span'); + + // $ExpectType JQuery + $('p').has(new HTMLElement()); + } + + function map() { + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return 'myVal'; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return ['myVal1', 'myVal2']; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return null; + }); + + // $ExpectType JQuery + $('p').map(function(index, domElement) { + // $ExpectType HTMLElement + this; + // $ExpectType number + index; + // $ExpectType HTMLElement + domElement; + + return undefined; + }); + } + + function slice() { + // $ExpectType JQuery + $('p').slice(0, 10); + + // $ExpectType JQuery + $('p').slice(0); + } + } } function JQueryStatic() { diff --git a/types/jquery/test/example-tests.ts b/types/jquery/test/example-tests.ts index 961e239192..bbb5d15d6c 100644 --- a/types/jquery/test/example-tests.ts +++ b/types/jquery/test/example-tests.ts @@ -4056,7 +4056,7 @@ function examples() { function promise_0() { var div = $('
'); - div.promise().done(function(this: JQuery, arg1: JQuery) { + div.promise().done(function(this: typeof div, arg1) { // Will fire right away and alert "true" alert(this === div && arg1 === div); });