DefinitelyTyped/types/jquery
Nathan Shively-Sanders c8089e91d1
Trim tsconfig files; move untested files to OTHER_FILES.txt (#40676)
* Initial cut

* fix aos global reference

* fix clearbladejs global references

* fix cldr.js augmentations

* fix codemirror compile errors (maybe)

* fixup skipped files after merge

* fix dwt/v13

* add missing references to adone

* fix meteor (manually)

* fix rangy

* add missing file reference to react-blessed

* fix react-dom?

* bump codemirror to 3.2

* bump dwt to 3.2

* Add/remove OTHER_FILES.txt as needed.

* bump react-codemirror to 3.2

* add references to slickgrid tests

* add reference to strophe.js tests

* add reference to strophe+fix types

* add reference to waypoints test

* Bump others to 3.9

* remove incorrectly added file

* Use more explicit types reference paths

* bump strophejs-plugin-roster TS version
2019-11-26 12:47:30 -08:00
..
dist
test
v1
v2
index.d.ts
jquery-tests.ts
JQuery.d.ts
JQueryStatic.d.ts
legacy.d.ts
misc.d.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;
}