DefinitelyTyped/types/jquery
segayuu 1a07f27101 [@types/Bluebird] Make iterative methods rigid types without type parameters. (#27216)
* Resolve bluebird(Array) method

* upgrade typescript version from bluebird-global

* move testfile
Reason: There are too many type definition files
  depending on jquery and it can not be managed.

* upgrade typescript version from bluebird require packages

* fix lint error: use-default-type-parameter
2018-07-12 09:23:46 -07:00
..
test [@types/Bluebird] Make iterative methods rigid types without type parameters. (#27216) 2018-07-12 09:23:46 -07:00
v1
v2
index.d.ts Merge pull request #26674 from leonard-thieu/jquery/jquerystatic-type-parameter 2018-06-19 12:46:05 -07:00
jquery-tests.ts [jquery] Add tests to cover the changed APIs. 2018-06-19 13:56:49 -04:00
README.md
tsconfig.json [@types/Bluebird] Make iterative methods rigid types without type parameters. (#27216) 2018-07-12 09:23:46 -07:00
tslint.json [jquery] Improve lint compliance. 2018-06-19 13:41:49 -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;
}