DefinitelyTyped/types/jquery
Leonard Thieu d883a9fd50 [jquery] Documentation improvements. Add jQuery.cleanData and overloads for jQuery.getScript and Data APIs. (#29573)
* [jquery] Introduce interface for `jQuery.fx`.

* [jquery] Attach `jQuery.Deferred` documentation to correct symbol.

* [jquery] Convert `jQuery.Callbacks` to an interface.

This change is purely for consistency with similar properties (e.g. `jQuery.Deferred`, `jQuery.Event`).

* [jquery] For `JQuery`, reduce examples to only those relevant to the overload and use shorter template for code-only examples.

* [jquery] For `JQueryStatic`, reduce examples to only those relevant to the overload and use shorter template for code-only examples.

* [jquery] For `JQuery.Event`, reduce examples to only those relevant to the overload and use shorter template for code-only examples.

* [jquery] For `JQuery.Callbacks`, reduce examples to only those relevant to the overload and use shorter template for code-only examples.

* [jquery] For `JQuery.PromiseBase`/`JQuery.Deferred`, reduce examples to only those relevant to the overload and use shorter template for code-only examples.

* [jquery] Consistent ordering.

* [jquery] Add `jQuery.getScript(options)`.

See https://github.com/jquery/api.jquery.com/issues/1052.

* [jquery] Fix documentation for this one overload of `jQuery.proxy`.

* [jquery] Accept `Document`, `Window`, and `JQuery.PlainObject` for the `element` parameter of Data APIs.

See 354f6036f2/test/unit/data.js (L142-L164) and https://github.com/jquery/api.jquery.com/issues/1035.

* [jquery] Add `jQuery.cleanData`.

See https://github.com/jquery/api.jquery.com/issues/996.
2018-10-09 08:34:57 -07:00
..
test [jquery] Drop type guards from isNumeric()/isPlainObject() and improve declarations of jQuery.data()/.data()/jQuery.css() (#29381) 2018-10-02 11:37:07 -07:00
v1
v2 [jquery] Change all HTMLElement to be Element (#29282) 2018-10-03 11:53:04 -07:00
index.d.ts [jquery] Documentation improvements. Add jQuery.cleanData and overloads for jQuery.getScript and Data APIs. (#29573) 2018-10-09 08:34:57 -07:00
jquery-tests.ts [jquery] Documentation improvements. Add jQuery.cleanData and overloads for jQuery.getScript and Data APIs. (#29573) 2018-10-09 08:34:57 -07:00
README.md
tsconfig.json
tslint.json

Usage

Global

When jQuery is globally available, you can use jQuery and $ directly.

Importing (with a global DOM available)

When you want to import jQuery as a module and have a global DOM available (e.g. browser and browser-like environments):

import jQuery = require('jquery');

Importing (without a global DOM available)

When you want to import jQuery as a module and do not have a global DOM available (e.g. Node.js environment):

import jQueryFactory = require('jquery');
const jQuery = jQueryFactory(window, true);

Note that while the factory function ignores the second parameter, it is required to get correct type declarations.

Project structure

Authoring type definitions for jQuery plugins

$.fn is represented by JQuery.

$ is represented by JQueryStatic.

Declare an interface that has the plugin's overloads as call signatures and static members as properties.

interface MyPlugin {
    settings: MyPluginSettings;
    
    (behavior: 'enable'): JQuery;
    (settings?: MyPluginSettings): JQuery;
}

interface MyPluginSettings {
    title?: string;
}

Then declare a property on JQuery with your plugin's type.

interface JQuery {
    myPlugin: MyPlugin;
}