DefinitelyTyped/types/jquery
2017-06-26 17:36:16 -04:00
..
test [jquery] Allow passing output of $.parseHTML() directly to manipulation methods. 2017-06-23 14:57:03 -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: Add null as a possible return value on val() 2017-06-26 14:21:19 +09:00
jquery-tests.ts jquery: Update test annotation 2017-06-26 17:58:28 +09: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] Update type definitions (new for v3). 2017-06-13 11:52:16 -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;
}