[jquery] Clean up methods on JQueryStatic.

Add tests for methods on JQueryStatic.
This commit is contained in:
Leonard Thieu
2017-06-23 12:31:10 -04:00
parent c898c05c77
commit a6390aea00
3 changed files with 858 additions and 84 deletions
+39 -46
View File
@@ -2411,7 +2411,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.4.3
*/
cssNumber: JQuery.PlainObject<boolean>;
readonly fn: JQuery;
readonly fn: JQuery<TElement>;
fx: {
/**
* The rate (in milliseconds) at which animations fire.
@@ -2436,7 +2436,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.ready/}
* @since 1.8
*/
ready: JQuery.Thenable<JQueryStatic>;
ready: JQuery.Thenable<JQueryStatic<TElement>>;
/**
* A collection of properties that represent the presence of different browser features or bugs.
* Intended for jQuery's internal use; specific properties may be removed when they are no longer
@@ -2489,7 +2489,9 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.0
* @since 1.4
*/
(selector_object_callback?: JQuery.Selector | JQuery.TypeOrArray<Element> | JQuery.PlainObject | JQuery | (($: JQueryStatic) => void)): JQuery<TElement>;
(selector_object_callback?: JQuery.Selector | JQuery.htmlString | JQuery.TypeOrArray<Element> | JQuery |
JQuery.PlainObject |
((this: Document, $: JQueryStatic<TElement>) => void)): JQuery<TElement>;
/**
* A multi-purpose callbacks list object that provides a powerful way to manage callback lists.
*
@@ -2629,7 +2631,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.each/}
* @since 1.0
*/
each<T>(array: ArrayLike<T>, callback: (indexInArray: number, value: T) => false | any): ArrayLike<T>;
each<T>(array: ArrayLike<T>, callback: (this: T, indexInArray: number, value: T) => false | any): ArrayLike<T>;
/**
* A generic iterator function, which can be used to seamlessly iterate over both objects and arrays.
* Arrays and array-like objects with a length property (such as a function's arguments object) are
@@ -2640,7 +2642,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.each/}
* @since 1.0
*/
each<T, K extends keyof T>(obj: T, callback: (propertyName: K, valueOfProperty: T[K]) => false | any): T;
each<T, K extends keyof T>(obj: T, callback: (this: T[K], propertyName: K, valueOfProperty: T[K]) => false | any): T;
/**
* Takes a string and throws an exception containing it.
*
@@ -2648,7 +2650,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.error/}
* @since 1.4.1
*/
error(message: string): never;
error(message: string): any;
/**
* Escapes any character that has a special meaning in a CSS selector.
*
@@ -2719,7 +2721,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.extend/}
* @since 1.1.4
*/
extend<T, U>(deep: true, target: T, ...objects: U[]): T & U;
extend(deep: true, target: any, object1: any, ...objects: any[]): any;
/**
* Merge the contents of two or more objects together into the first object.
*
@@ -2782,7 +2784,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.extend/}
* @since 1.0
*/
extend<T, U>(target: T, ...objects: U[]): T & U;
extend(target: any, object1: any, ...objects: any[]): any;
/**
* Load data from the server using a HTTP GET request.
*
@@ -2835,7 +2837,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.12
* @since 2.2
*/
get(url_settings?: string | JQuery.AjaxSettings): JQuery.jqXHR;
get(url_settings?: string | JQuery.UrlAjaxSettings): JQuery.jqXHR;
/**
* Load JSON-encoded data from the server using a GET HTTP request.
*
@@ -2868,7 +2870,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.0
*/
getScript(url: string,
success?: JQuery.jqXHR.DoneCallback<string | undefined>): JQuery.jqXHR;
success?: JQuery.jqXHR.DoneCallback<string | undefined>): JQuery.jqXHR<string | undefined>;
/**
* Execute some JavaScript code globally.
*
@@ -2915,7 +2917,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.htmlPrefilter/}
* @since 1.12/2.2
*/
htmlPrefilter(html: string): string;
htmlPrefilter(html: JQuery.htmlString): JQuery.htmlString;
/**
* Search for a specified value within an array and return its index (or -1 if not found).
*
@@ -3029,7 +3031,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.noConflict/}
* @since 1.0
*/
noConflict(removeAll?: boolean): JQueryStatic;
noConflict(removeAll?: boolean): this;
/**
* An empty function.
*
@@ -3145,7 +3147,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.12
* @since 2.2
*/
post(url_settings?: string | JQuery.AjaxSettings): JQuery.jqXHR;
post(url_settings?: string | JQuery.UrlAjaxSettings): JQuery.jqXHR;
/**
* Takes a function and returns a new one that will always have a particular context.
*
@@ -3178,16 +3180,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.queue/}
* @since 1.3
*/
queue(element: Element, queueName: string, newQueue: JQuery.TypeOrArray<JQuery.QueueFunction<Element>>): JQuery;
/**
* Show the queue of functions to be executed on the matched element.
*
* @param element A DOM element to inspect for an attached queue.
* @param queueName A string containing the name of the queue. Defaults to fx, the standard effects queue.
* @see {@link https://api.jquery.com/jQuery.queue/}
* @since 1.3
*/
queue(element: Element, queueName?: string): JQuery.Queue<TElement>;
queue<T extends Element>(element: T, queueName?: string, newQueue?: JQuery.TypeOrArray<JQuery.QueueFunction<T>>): JQuery.Queue<T>;
/**
* Handles errors thrown synchronously in functions wrapped in jQuery().
*
@@ -3204,7 +3197,7 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @see {@link https://api.jquery.com/jQuery.removeData/}
* @since 1.2.3
*/
removeData(element: Element, name?: string): JQuery;
removeData(element: Element, name?: string): void;
/**
* Creates an object containing a set of properties ready to be used in the definition of custom animations.
*
@@ -3215,38 +3208,28 @@ interface JQueryStatic<TElement extends Node = HTMLElement> {
* @since 1.1
*/
speed(duration: JQuery.Duration, easing: string, complete: (this: TElement) => void): JQuery.EffectsOptions<TElement>;
/**
* Creates an object containing a set of properties ready to be used in the definition of custom animations.
*
* @param easing A string indicating which easing function to use for the transition.
* @param complete A function to call once the animation is complete, called once per matched element.
* @see {@link https://api.jquery.com/jQuery.speed/}
* @since 1.1
*/
speed(easing: string, complete: (this: TElement) => void): JQuery.EffectsOptions<TElement>;
/**
* Creates an object containing a set of properties ready to be used in the definition of custom animations.
*
* @param duration A string or number determining how long the animation will run.
* @param easing_complete_settings A string indicating which easing function to use for the transition.
* A function to call once the animation is complete, called once per matched element.
* @param easing_complete A string indicating which easing function to use for the transition.
* A function to call once the animation is complete, called once per matched element.
* @see {@link https://api.jquery.com/jQuery.speed/}
* @since 1.0
* @since 1.1
*/
speed(duration: JQuery.Duration,
easing_complete_settings: string | ((this: TElement) => void) | JQuery.SpeedSettings<TElement>): JQuery.EffectsOptions<TElement>;
easing_complete: string | ((this: TElement) => void)): JQuery.EffectsOptions<TElement>;
/**
* Creates an object containing a set of properties ready to be used in the definition of custom animations.
*
* @param duration_easing_complete_settings A string or number determining how long the animation will run.
* A string indicating which easing function to use for the transition.
* A function to call once the animation is complete, called once per matched element.
* @param duration_complete_settings A string or number determining how long the animation will run.
* A function to call once the animation is complete, called once per matched element.
* @see {@link https://api.jquery.com/jQuery.speed/}
* @since 1.0
* @since 1.1
*/
speed(duration_easing_complete_settings?: JQuery.Duration | string | ((this: TElement) => void) | JQuery.SpeedSettings<TElement>): JQuery.EffectsOptions<TElement>;
speed(duration_complete_settings?: JQuery.Duration | ((this: TElement) => void) | JQuery.SpeedSettings<TElement>): JQuery.EffectsOptions<TElement>;
/**
* Remove the whitespace from the beginning and end of a string.
*
@@ -3325,10 +3308,24 @@ declare namespace JQuery {
// region Ajax
interface AjaxSettings<TContext = any> extends AjaxSettingsBase<TContext> {
/**
* A string containing the URL to which the request is sent.
*/
url?: string;
}
interface UrlAjaxSettings<TContext = any> extends AjaxSettingsBase<TContext> {
/**
* A string containing the URL to which the request is sent.
*/
url: string;
}
/**
* @see {@link http://api.jquery.com/jquery.ajax/#jQuery-ajax-settings}
*/
interface AjaxSettings<TContext = any> {
interface AjaxSettingsBase<TContext> {
/**
* A set of key/value pairs that map a given dataType to its MIME type, which gets sent in the Accept
* request header. This header tells the server what kind of response it will accept in return.
@@ -3350,7 +3347,7 @@ declare namespace JQuery {
* function will cancel the request. As of jQuery 1.5, the beforeSend option will be called regardless
* of the type of request.
*/
beforeSend?(this: TContext, jqXHR: jqXHR, settings: AjaxSettings<TContext>): false | void;
beforeSend?(this: TContext, jqXHR: jqXHR, settings: AjaxSettingsBase<TContext>): false | void;
/**
* If set to false, it will force requested pages not to be cached by the browser. Note: Setting cache
* to false will only work correctly with HEAD and GET requests. It works by appending "_={timestamp}"
@@ -3559,10 +3556,6 @@ declare namespace JQuery {
* An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.
*/
type?: string;
/**
* A string containing the URL to which the request is sent.
*/
url?: string;
/**
* A username to be used with XMLHttpRequest in response to an HTTP access authentication request.
*/
+818 -37
View File
@@ -3475,18 +3475,65 @@ function JQueryStatic() {
const jq: JQueryStatic = $;
}
function constructor() {
function selector_object_callback() {
const jq = $ as JQueryStatic<Node>;
// $ExpectType JQuery<Node>
jq('div');
}
function call_signature() {
// #ExpectType JQuery<HTMLElement>
$('<p></p>', new Document());
// #ExpectType JQuery<HTMLElement>
$('<p></p>', {
class: 'my-div',
on: {
touchstart() {
// Do something
}
}
});
// #ExpectType JQuery<HTMLElement>
$('span', new HTMLElement());
// #ExpectType JQuery<HTMLElement>
$('span', new Document());
// #ExpectType JQuery<HTMLElement>
$('span', $('p'));
// #ExpectType JQuery<HTMLElement>
$('span');
// #ExpectType JQuery<HTMLElement>
$('<p></p>');
// #ExpectType JQuery<HTMLElement>
$(new HTMLElement());
// #ExpectType JQuery<HTMLElement>
$([new HTMLElement()]);
// #ExpectType JQuery<HTMLElement>
$({ foo: 'bar', hello: 'world' });
// #ExpectType JQuery<HTMLElement>
$($('p'));
// #ExpectType JQuery<HTMLElement>
$(function($) {
// #ExpectType Document
this;
// #ExpectType JQueryStatic<HTMLElement>
$;
});
// #ExpectType JQuery<HTMLElement>
$();
}
function Callbacks() {
const cb = $.Callbacks();
// #ExpectType Callbacks
$.Callbacks('once');
cb.add(console.log);
// #ExpectType Callbacks
$.Callbacks();
}
function Event() {
@@ -3496,26 +3543,468 @@ function JQueryStatic() {
}
}
function ajax() {
// $ExpectType jqXHR<any>
$.ajax('url', {
cache: true
});
}
function ajaxPrefilter() {
// $ExpectType void
$.ajaxPrefilter('dataTypes', (options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
return 'filtered';
});
// $ExpectType void
$.ajaxPrefilter('dataTypes', (options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
});
// $ExpectType void
$.ajaxPrefilter((options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
return 'filtered';
});
// $ExpectType void
$.ajaxPrefilter((options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
});
}
function ajaxSetup() {
// $ExpectType AjaxSettings<any>
$.ajaxSetup({
cache: true
});
}
function ajaxTransport() {
// $ExpectType void
$.ajaxTransport('dataTypes', (options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
return {
send(headers, completeCallback) {
// $ExpectType PlainObject<any>
headers;
// $ExpectType SuccessCallback
completeCallback;
},
abort() { }
};
});
// $ExpectType void
$.ajaxTransport('dataTypes', (options, originalOptions, jqXHR) => {
// $ExpectType AjaxSettings<any>
options;
// $ExpectType AjaxSettings<any>
originalOptions;
// $ExpectType jqXHR<any>
jqXHR;
});
}
function contains() {
// $ExpectType boolean
$.contains(new HTMLElement(), new HTMLElement());
}
function css() {
// $ExpectType any
$.css(new HTMLElement(), {});
}
function data() {
// $ExpectType any
$.data(new HTMLElement(), 'myKey', undefined);
// $ExpectType "myValue"
$.data(new HTMLElement(), 'myKey', 'myValue');
// $ExpectType any
$.data(new HTMLElement(), 'myKey');
// $ExpectType any
$.data(new HTMLElement());
}
function dequeue() {
// $ExpectType void
$.dequeue(new HTMLElement(), 'myQueue');
// $ExpectType void
$.dequeue(new HTMLElement());
}
function each() {
function arrayLike() {
$.each({ length: 3 }, (index, val) => {
index === 3;
});
}
// $ExpectType ArrayLike<string>
$.each(['myVal1', 'myVal2'], function(index, val) {
// $ExpectType string
this;
// $ExpectType number
index;
// $ExpectType string
val;
return false;
});
// $ExpectType ArrayLike<string>
$.each(['myVal1', 'myVal2'], function(index, val) {
// $ExpectType string
this;
// $ExpectType number
index;
// $ExpectType string
val;
return 10;
});
// $ExpectType ArrayLike<string>
$.each(['myVal1', 'myVal2'], function(index, val) {
// $ExpectType string
this;
// $ExpectType number
index;
// $ExpectType string
val;
});
// $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; }
$.each({
myVal1: false,
myVal2: () => {
return 10;
},
myVal3: 'myVal3'
}, function(propertyName, valueOfProperty) {
// $ExpectType string | boolean | (() => 10)
this;
// $ExpectType "myVal1" | "myVal2" | "myVal3"
propertyName;
// $ExpectType string | boolean | (() => 10)
valueOfProperty;
return false;
});
// $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; }
$.each({
myVal1: false,
myVal2: () => {
return 10;
},
myVal3: 'myVal3'
}, function(propertyName, valueOfProperty) {
// $ExpectType string | boolean | (() => 10)
this;
// $ExpectType "myVal1" | "myVal2" | "myVal3"
propertyName;
// $ExpectType string | boolean | (() => 10)
valueOfProperty;
return 10;
});
// $ExpectType { myVal1: boolean; myVal2: () => 10; myVal3: string; }
$.each({
myVal1: false,
myVal2: () => {
return 10;
},
myVal3: 'myVal3'
}, function(propertyName, valueOfProperty) {
// $ExpectType string | boolean | (() => 10)
this;
// $ExpectType "myVal1" | "myVal2" | "myVal3"
propertyName;
// $ExpectType string | boolean | (() => 10)
valueOfProperty;
});
}
function error() {
jQuery.error = console.error;
}
function escapeSelector() {
// $ExpectType string
$.escapeSelector('span');
}
function extend() {
const t = { name: 'myObj' };
const u = new EventTarget();
const v = new Node();
const w = new Comment();
const x = new Text();
const y = new Element();
const z = new HTMLElement();
const a = new SVGElement();
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element & HTMLElement
$.extend(true, t, u, v, w, x, y, z);
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element
$.extend(true, t, u, v, w, x, y);
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text
$.extend(true, t, u, v, w, x);
// $ExpectType { name: string; } & EventTarget & Node & Comment
$.extend(true, t, u, v, w);
// $ExpectType { name: string; } & EventTarget & Node
$.extend(true, t, u, v);
// $ExpectType { name: string; } & EventTarget
$.extend(true, t, u);
// $ExpectType any
$.extend(true, t, u, v, w, x, y, z, a);
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element & HTMLElement
$.extend(t, u, v, w, x, y, z);
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text & Element
$.extend(t, u, v, w, x, y);
// $ExpectType { name: string; } & EventTarget & Node & Comment & Text
$.extend(t, u, v, w, x);
// $ExpectType { name: string; } & EventTarget & Node & Comment
$.extend(t, u, v, w);
// $ExpectType { name: string; } & EventTarget & Node
$.extend(t, u, v);
// $ExpectType { name: string; } & EventTarget
$.extend(t, u);
// $ExpectType any
$.extend(t, u, v, w, x, y, z, a);
}
function get() {
// $ExpectType jqXHR<any>
$.get('url', { myData: 'myData' }, (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.get('url', 'myData', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.get('url', { myData: 'myData' }, null, 'script');
// $ExpectType jqXHR<any>
$.get('url', 'myData', null, 'script');
// $ExpectType jqXHR<any>
$.get('url', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.get('url', null, 'script');
// $ExpectType jqXHR<any>
$.get('url', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.get('url', { myData: 'myData' });
// $ExpectType jqXHR<any>
$.get('url', 'myData');
// $ExpectType jqXHR<any>
$.get('url');
// $ExpectType jqXHR<any>
$.get({ url: 'url' });
// $ExpectType jqXHR<any>
$.get();
}
function getJSON() {
// $ExpectType jqXHR<any>
$.getJSON('url', { myVal1: 'myVal1' }, (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
});
// $ExpectType jqXHR<any>
$.getJSON('url', 'myVal1', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
});
// $ExpectType jqXHR<any>
$.getJSON('url', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
});
// $ExpectType jqXHR<any>
$.getJSON('url', { myVal1: 'myVal1' });
// $ExpectType jqXHR<any>
$.getJSON('url', 'myVal1');
// $ExpectType jqXHR<any>
$.getJSON('url');
}
function getScript() {
// $ExpectType jqXHR<string | undefined>
$.getScript('url', (data, textStatus, jqXHR) => {
// $ExpectType string | undefined
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<string | undefined>
jqXHR;
});
}
function globalEval() {
// $ExpectType void
$.globalEval('throw new Error();');
}
function grep() {
// $ExpectType string[]
$.grep(['myVal1', 'myVal2'], (elementOfArray, indexInArray) => {
// $ExpectType string
elementOfArray;
// $ExpectType number
indexInArray;
return true;
}, true);
// $ExpectType string[]
$.grep(['myVal1', 'myVal2'], (elementOfArray, indexInArray) => {
// $ExpectType string
elementOfArray;
// $ExpectType number
indexInArray;
return true;
});
}
function hasData() {
// $ExpectType boolean
$.hasData(new HTMLElement());
}
function holdReady() {
// $ExpectType void
$.holdReady(true);
}
function htmlPrefilter() {
// $ExpectType string
$.htmlPrefilter('<span></span>');
}
function inArray() {
// $ExpectType number
$.inArray(1, [1, 2], 1);
// $ExpectType number
$.inArray(1, [1, 2]);
}
function isArray() {
function type_guard(obj: object) {
if ($.isArray(obj)) {
console.log(obj[0]);
// $ExpectType any[]
obj;
}
}
}
function isEmptyObject() {
// $ExpectType boolean
$.isEmptyObject({});
}
function isFunction() {
function type_guard(obj: object) {
if ($.isFunction(obj)) {
obj();
// $ExpectType Function
obj;
}
}
}
@@ -3523,7 +4012,8 @@ function JQueryStatic() {
function isNumeric() {
function type_guard(obj: boolean) {
if ($.isNumeric(obj)) {
obj.toFixed();
// $ExpectType (true & number) | (false & number)
obj;
}
}
}
@@ -3531,7 +4021,8 @@ function JQueryStatic() {
function isPlainObject() {
function type_guard(obj: object) {
if ($.isPlainObject(obj)) {
obj['key'] = true;
// $ExpectType PlainObject<any>
obj;
}
}
}
@@ -3539,37 +4030,239 @@ function JQueryStatic() {
function isWindow() {
function type_guard(obj: object) {
if ($.isWindow(obj)) {
obj.location.href === 'href';
// $ExpectType Window
obj;
}
}
}
function isXMLDoc() {
// $ExpectType boolean
$.isXMLDoc(new Node());
}
function makeArray() {
// $ExpectType number[]
$.makeArray([1, 2]);
}
function map() {
function object() {
const testObj = {
myProp: true,
name: 'Rogers',
};
// $ExpectType number[]
$.map([1, 2, 3], (elementOfArray, indexInArray) => {
// $ExpectType number
elementOfArray;
// $ExpectType number
indexInArray;
const results = $.map(testObj, (propertyOfObject, key) => {
switch (key) {
case 'myProp':
return 1;
case 'name':
return false;
}
});
return 200 + 10;
});
for (const result of results) {
result === 1;
// $ExpectType (false | 1)[]
$.map({
myProp: true,
name: 'Rogers',
}, (propertyOfObject, key) => {
// $ExpectType string | boolean
propertyOfObject;
// $ExpectType "myProp" | "name"
key;
switch (key) {
case 'myProp':
return 1;
case 'name':
return false;
}
}
});
}
function merge() {
// $ExpectType (string | number)[]
$.merge([1, 2, 3], ['myVal1', 'myVal2']);
}
function noConflict() {
// $ExpectType JQueryStatic<HTMLElement>
$.noConflict(true);
// $ExpectType JQueryStatic<HTMLElement>
$.noConflict();
}
function noop() {
// $ExpectType undefined
$.noop();
}
function now() {
// $ExpectType number
$.now();
}
function param() {
// $ExpectType string
$.param([true, 20], true);
// $ExpectType string
$.param({
myVal1: true,
myVal2: 20
}, true);
// $ExpectType string
$.param($('input'), true);
// $ExpectType string
$.param([true, 20]);
// $ExpectType string
$.param({
myVal1: true,
myVal2: 20
});
// $ExpectType string
$.param($('input'));
}
function parseHTML() {
// $ExpectType Node[]
$.parseHTML('<span></span>', document, true);
// $ExpectType Node[]
$.parseHTML('<span></span>', null, true);
// $ExpectType Node[]
$.parseHTML('<span></span>', undefined, true);
// $ExpectType Node[]
$.parseHTML('<span></span>', document);
// $ExpectType Node[]
$.parseHTML('<span></span>', null);
// $ExpectType Node[]
$.parseHTML('<span></span>', undefined);
// $ExpectType Node[]
$.parseHTML('<span></span>', false);
// $ExpectType Node[]
$.parseHTML('<span></span>');
}
function parseJSON() {
// $ExpectType any
$.parseJSON('{}');
}
function parseXML() {
// $ExpectType XMLDocument
$.parseXML('<xml></xml>');
}
function post() {
// $ExpectType jqXHR<any>
$.post('url', { myData: 'myData' }, (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.post('url', 'myData', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.post('url', { myData: 'myData' }, null, 'script');
// $ExpectType jqXHR<any>
$.post('url', 'myData', null, 'script');
// $ExpectType jqXHR<any>
$.post('url', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.post('url', null, 'script');
// $ExpectType jqXHR<any>
$.post('url', (data, textStatus, jqXHR) => {
// $ExpectType any
data;
// $ExpectType SuccessTextStatus
textStatus;
// $ExpectType jqXHR<any>
jqXHR;
}, 'script');
// $ExpectType jqXHR<any>
$.post('url', { myData: 'myData' });
// $ExpectType jqXHR<any>
$.post('url', 'myData');
// $ExpectType jqXHR<any>
$.post('url');
// $ExpectType jqXHR<any>
$.post({ url: 'url' });
// $ExpectType jqXHR<any>
$.post();
}
function proxy() {
// $ExpectType Function
$.proxy($.noop, {}, 1, 2);
// $ExpectType Function
$.proxy($.noop, {});
// $ExpectType Function
$.proxy({ myFunc: $.noop }, 'myFunc', 1, 2);
// $ExpectType Function
$.proxy({ myFunc: $.noop }, 'myFunc');
}
function queue() {
const el = new HTMLElement();
const queue = jQuery.queue(el);
queue[0] === 'inprogress';
// $ExpectType Queue<HTMLElement>
$.queue(new HTMLElement(), 'myQueue', function(next) {
// $ExpectType HTMLElement
this;
// $ExpectType () => void
next;
});
// $ExpectType Queue<HTMLElement>
$.queue(new HTMLElement(), 'myQueue', [function(next) {
// $ExpectType HTMLElement
this;
// $ExpectType () => void
next;
}]);
// $ExpectType Queue<HTMLElement>
$.queue(new HTMLElement(), 'myQueue');
// $ExpectType Queue<HTMLElement>
$.queue(new HTMLElement());
}
function readyException() {
@@ -3577,6 +4270,94 @@ function JQueryStatic() {
console.error(error);
};
}
function removeData() {
// $ExpectType void
$.removeData(new HTMLElement(), 'test1');
// $ExpectType void
$.removeData(new HTMLElement());
}
function speed() {
// $ExpectType EffectsOptions<HTMLElement>
$.speed(5000, 'linear', function() {
// $ExpectType HTMLElement
this;
});
// $ExpectType EffectsOptions<HTMLElement>
$.speed(5000, 'linear');
// $ExpectType EffectsOptions<HTMLElement>
$.speed(5000, function() {
// $ExpectType HTMLElement
this;
});
// $ExpectType EffectsOptions<HTMLElement>
$.speed(5000);
// $ExpectType EffectsOptions<HTMLElement>
$.speed(function() {
// $ExpectType HTMLElement
this;
});
// $ExpectType EffectsOptions<HTMLElement>
$.speed({
duration: 5000,
easing: 'linear',
complete() {
// $ExpectType HTMLElement
this;
}
});
// $ExpectType EffectsOptions<HTMLElement>
$.speed();
}
function trim() {
// $ExpectType string
$.trim('myStr');
}
function type() {
// $ExpectType "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" | "error" | "array" | "date" | "null" | "regexp"
$.type({});
}
function unique() {
// $ExpectType HTMLElement[]
$.unique([new HTMLElement()]);
}
function uniqueSort() {
// $ExpectType HTMLElement[]
$.uniqueSort([new HTMLElement()]);
}
function when() {
const t = $.ajax() as JQuery.jqXHR<string>;
const u = $.ajax() as JQuery.jqXHR<number>;
const v = $.ajax() as JQuery.jqXHR<boolean>;
// $ExpectType Promise<[string | number | boolean, string, jqXHR<string | number | boolean>], any, any>
$.when(t, u, v);
// $ExpectType Promise<[string | number, string, jqXHR<string | number>], any, any>
$.when(t, u);
// $ExpectType Promise<string | jqXHR<string>, any, any>
$.when(t);
// $ExpectType Promise<any, any, any>
$.when($.Deferred());
// $ExpectType Promise<any, any, any>
$.when();
}
}
function EffectsOptions() {
+1 -1
View File
@@ -2434,7 +2434,7 @@ function examples() {
}
function jQuery_error_0() {
jQuery.error = console.error as any;
jQuery.error = console.error;
}
function jQuery_escape_selector_0() {