简体   繁体   English

如何获取特定版本的Jquery,ex 3.2.1的TypeScript定义文件?

[英]How to get TypeScript definitions file for a particular version of Jquery, ex 3.2.1?

I'm new to TypeScript and still trying to figure it out. 我是TypeScript的新手,仍在努力解决这个问题。 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. 我有一个使用jquery版本3.2.1的示例visual studio项目,我想让我的项目可以使用TypeScript类型定义。

From the internet it appears that the authoritative source for these type definitions is https://github.com/DefinitelyTyped/DefinitelyTyped 从互联网上看,这些类型定义的权威来源似乎是https://github.com/DefinitelyTyped/DefinitelyTyped

On that page I read 在那页上,我读到了

npm NPM
This is the preferred method. 这是首选方法。 This is only available for TypeScript 2.0+ users. 这仅适用于TypeScript 2.0+用户。 For example: 例如:

npm install --save-dev @types/node 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. 所以看起来我只需要键入npm install --save-dev @types/jquery来获取通过npm下载的jquery类型定义文件。 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. 但后来我问自己,嗯,我想知道如果每个人都在键入相同的命令而不管jquery版本,那么类型定义文件将是什么版本的jquery。 So I went over to the npm site to check and oddly it said 所以我去了npm网站检查,奇怪的是它说

This package contains type definitions for jQuery 1.10.x / ( http://jquery.com/ ). 这个软件包包含的jQuery 1.10.x /(类型定义http://jquery.com/ )。

yet, the last update was "Last updated: Sat, 11 Mar 2017 00:13:28 GMT". 然而,最后一次更新是“最后更新:星期六,2017年3月11日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? 所以这看起来很奇怪,为什么最近会有一个针对jquery 1.10.x的npm模块的更新? And why would the latest version of the jquery type def on npm be for such an old version of jquery? 为什么npm的jquery类型def的最新版本是针对这样一个旧版本的jquery? 2.0 maybe but 1.10.x? 2.0也许只有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? 所以我猜测也许这些类型的defs是最新的和最好的,谁维护npm包只是不更新​​摘要? 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. 我下载了模块,并试图从类型defs的jquery版本中辨别出但是无法确定。

So here's my question. 所以这是我的问题。 How does a person get TypeScript definitions file for a particular version of Jquery, ex 3.2.1? 一个人如何获得特定版本的Jquery,ex 3.2.1的TypeScript定义文件?

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. 嗨,有点晚了,但这是我在查看index.d.ts文件后发现的,第一行中的注释说明了兼容JQuery的版本。

npm install @types/jquery@1.x will get you JQuery 1.x definitions npm install @types/jquery@1.x将为您提供JQuery 1.x定义

npm install @types/jquery@2.x will get you JQuery 2.x definitions npm install @types/jquery@2.x将为您提供JQuery 2.x定义

npm install @types/jquery@3.x will get you JQuery 3.x definitions npm install @types/jquery@3.x将为您提供JQuery 3.x定义

You can print all version of specific npm package using one of these two commands: 您可以使用以下两个命令之一打印所有版本的特定npm包:

npm view package-name versions

OR 要么

npm i package-name@whatever (You'll get an error, but it prints all available versions) npm i package-name@whatever (你会得到一个错误,但它打印所有可用的版本)

Then just install specific version by running: 然后运行以下命令安装特定版本:

npm i package-name@version


So for jquery types you would run: 因此,对于jquery类型,您将运行:

npm view @types/jquery versions

You see all the versions (currently latest 2.0.41). 你看到所有的版本(目前最新的2.0.41)。 You install specific version: 您安装特定版本:

npm install --save-dev @types/jquery@2.0.41

The types you're getting now are the most recent version of the types for jQuery. 您现在获得的类型是jQuery类型的最新版本。

There weren't many changes between 1.10.x and 2.0.x, so the type definitions work for both. 1.10.x和2.0.x之间没有太多变化,因此类型定义适用于两者。

There's an issue on GitHub in which someone asks for new definitions for jQuery 3.x. 在GitHub上一个问题 ,有人要求为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. 不幸的是,没有人自愿为更高版本的jQuery添加类型定义,因此它们将保留在那些旧版本中,直到有人这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM