types/jquery/README.md
When jQuery is globally available, you can use jQuery and $ directly.
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');
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.
test/jquery-window-module-tests.ts
test/jquery-slim-window-module-tests.ts
test/jquery-no-window-module-tests.ts
test/jquery-slim-no-window-module-tests.ts
$.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;
}