Typescript jQuery definition

190 Views Asked by At

The current version of the jQuery Typescript definition specifies that it contains the

Type definitions for jQuery 1.10.x / 2.0.x

Does this imply that it contains a consolidated single version covering all versions between 1.10.x / 2.0.x?

If so, how are deprecated methods and changes to method signatures handled?

Additionally how does one safely use these definitions if you are targeting a version of jQuery lower than 2.0.x

For instance, its possible that a new method gets introduced in 2.0.3, but our code currently targets version 1.x.x.

Typescript will allow me to call that new method (because its in the jquery.t.ds), but the call will fail at runtime because its not present in the version of the actual jQuery library in use.

I feel like I'm missing something fundamental here.

2

There are 2 best solutions below

0
On BEST ANSWER

It contains the definitions for both versions. That's possible due the fact, that there are no deprecations between 1.9+ and 2.0. The difference is just the browser compatibility (2.0 drops support for IE7 and IE8, therefore the major release).

0
On

I believe that you are right about the consolidated version. Take a look at some definitions:

/**
 * A selector representing selector passed to jQuery(), if any, when creating the original set.
 * version deprecated: 1.7, removed: 1.9
 */
selector: string;
[index: string]: any;
[index: number]: HTMLElement;

It seems it will break on later versions if you don't read the comments.

If you want to "break" your compilation, I believe you should edit this definition file (not an option in the way I build my project) and remove the deprecated/removed versions.