DefinitelyTyped/types/jquery
Leonard Thieu 10f0a52b7f [jquery] Remove Promise1.
Promise1 is not being used.
2017-07-02 11:13:40 -04:00
..
test [jquery] offset() can return undefined on empty sets. 2017-06-26 08:00:00 -04:00
v1 [angular][jquery] Fix merge issue with cssPropertySetter. 2017-06-26 17:36:16 -04:00
v2 [angular][jquery] Fix merge issue with cssPropertySetter. 2017-06-26 17:36:16 -04:00
index.d.ts [jquery] Remove Promise1. 2017-07-02 11:13:40 -04:00
jquery-tests.ts [jquery] Fix uncaught test errors. 2017-07-02 10:28:55 -04:00
README.md [jquery] Add documentation describing project structure. 2017-06-23 16:43:32 -04:00
tsconfig.json [jquery] Fix imported JQueryStatic not returning a JQuery object when called with window. 2017-06-19 13:36:58 -04:00
tslint.json [jquery] Add Promise type that supports 3 parameters. 2017-06-25 13:52:07 -04:00

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;
}