DefinitelyTyped/types/jquery
Armando Aguirre c5797de356
Merge pull request #23921 from O-Zone/master
Jquery: Added Window to selector_object_callback type so $(window) is possible
2018-03-08 16:06:54 -08:00
..
test fix import in another test 2018-02-21 18:10:15 -05:00
v1 jQuery offset method might return undefined (#23821) 2018-02-26 11:47:25 -08:00
v2 jQuery offset method might return undefined (#23821) 2018-02-26 11:47:25 -08:00
index.d.ts Update index.d.ts 2018-02-26 09:40:41 +01:00
jquery-tests.ts
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;
}