DefinitelyTyped/types/jquery
Nathan Shively-Sanders fc1a495675
Dom fixes 2019 07 11 (#36837)
* Jquery, webappsec-credential-mangment, webgl2

1. `$(window)` will have a different type in TS 3.6,
`JQuery<Window & typeof globalThis>`, so ExpectType
assertions won't work anymore. I weakened the test to test
assignability:

```ts
const jqw: JQuery<Window> = $(window);
```

2. webappsec-credential-management needs to avoid conflicts with the DOM
version that 3.6 will include in order to keep compiling. I copied
interfaces and inlined type aliases where needed.

Inlining type aliases is not the ideal solution, but they don't merge,
so I couldn't copy them like interfaces. And they are (1) used only once
or twice (2) self-explanatory literal unions, so I think it's fine for a
package that will see reduced use once 3.6 is released.

3. webgl2 is also now in the DOM, so the polyfill types need to match
exactly. I deleted an extra property. Again, I expect this package to
stop being used as much once 3.6 is released.

* Rename CredentialData instead of deleting it

* Re-add CredentialData, CredentialBase->Credential

CredentialBase becomes an interface too, which more closely matches the
code in TS 3.6.

* Bump version of webappsec-credential-management
2019-07-11 14:14:34 -07: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;
}