Reputation: 33791
I'm new to TypeScript and still trying to figure it out. I have a sample visual studio project that uses jquery version 3.2.1 and I'd like to make the TypeScript type definitions available to my project.
From the internet it appears that the authoritative source for these type definitions is https://github.com/DefinitelyTyped/DefinitelyTyped
On that page I read
npm
This is the preferred method. This is only available for TypeScript 2.0+ users. For example:
npm install --save-dev @types/node
So it would seem I just need to type npm install --save-dev @types/jquery
to get the jquery type definition file downloaded via npm. But then I asked myself, hmm, I wonder what version of jquery those the type definition file will be for if everyone is typing the same command regardless of jquery version. So I went over to the npm site to check and oddly it said
This package contains type definitions for jQuery 1.10.x / (http://jquery.com/).
yet, the last update was "Last updated: Sat, 11 Mar 2017 00:13:28 GMT".
So that just seems odd, why would there be a recent update to an npm module that is for jquery 1.10.x? And why would the latest version of the jquery type def on npm be for such an old version of jquery? 2.0 maybe but 1.10.x? So I'm guessing that perhaps these type defs are the latest and greatest and whoever is maintaining the npm package just isn't updating the summary? But how can I confirm that? I downloaded the module and tried to discern from that what version of jquery the type defs were for but was unable to tell for sure.
So here's my question. How does a person get TypeScript definitions file for a particular version of Jquery, ex 3.2.1?
Upvotes: 4
Views: 4651
Reputation: 822
Hi a little late to this but this is what I found after I looked in the index.d.ts file, a comment in the first line states the version of compatible JQuery.
npm install @types/[email protected]
will get you JQuery 1.x definitions
npm install @types/[email protected]
will get you JQuery 2.x definitions
npm install @types/[email protected]
will get you JQuery 3.x definitions
Upvotes: 12
Reputation: 2935
You can print all version of specific npm package using one of these two commands:
npm view package-name versions
OR
npm i package-name@whatever
(You'll get an error, but it prints all available versions)
Then just install specific version by running:
npm i package-name@version
So for jquery types you would run:
npm view @types/jquery versions
You see all the versions (currently latest 2.0.41). You install specific version:
npm install --save-dev @types/[email protected]
Upvotes: 3
Reputation: 12112
The types you're getting now are the most recent version of the types for jQuery.
There weren't many changes between 1.10.x and 2.0.x, so the type definitions work for both.
There's an issue on GitHub in which someone asks for new definitions for jQuery 3.x. Unfortunately, no one's volunteered to add type definitions for later versions of jQuery, so they'll remain at those older versions until someone does.
Upvotes: 1