我可以从哪里获得最新的 typescript JQuery 定义文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13347918/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:46:25  来源:igfitidea点击:

Where can I get the latest typescript JQuery definition file from?

typescript

提问by Samantha J T Star

I know there are some problems with the definition file that I have already downloaded. For example here with the following $.ajax call:

我知道我已经下载的定义文件存在一些问题。例如这里使用以下 $.ajax 调用:

$.ajax("/Admin/xx",
{
    cache: false
})

Note that I need to specify the URL first. I recall reading that this was understood as an error.

请注意,我需要先指定 URL。我记得读到这被理解为一个错误。

Where can I get the latest JQuery definition file from. Anyone have any news as to when Microsoft will come out with an update to the Alpha version of Typescript that they have now?

我可以从哪里获得最新的 JQuery 定义文件。任何人都知道微软何时会发布他们现在拥有的 Typescript Alpha 版本的更新?

采纳答案by Fenton

Update! The Definitely Typed projectis now the correct place to grab your definitions - and Microsoft are now actively involved with Definitely Typed.

更新!在肯定类型化项目现在是抓住你的定义正确的地方-和现在微软正在积极地参与绝对键入。

The very latest official typing for jQuerycan be found on the TypeScript Codeplex site. (Link correct as of today).

可以在 TypeScript Codeplex 站点上找到最新的 jQuery官方类型。(截至今天链接正确)。

I believe the definition is currently:

我相信目前的定义是:

ajax(url: string, settings: JQueryAjaxSettings);

This is correct, but it is not the only variation of the ajaxfunction, it should really be overloaded with a definition for:

这是正确的,但它不是该ajax函数的唯一变体,它确实应该用以下定义重载:

ajax(settings: JQueryAjaxSettings);

You could add support to this in your own code by adding your own extension on top of the TypeScript jquery.d.ts definition and remove this when the jquery.d.ts file gets updated - when it is, you'll get a build warning about a duplicate definition to remind you to do this.

您可以通过在 TypeScript jquery.d.ts 定义之上添加您自己的扩展并在 jquery.d.ts 文件更新时删除它,在您自己的代码中添加对此的支持 - 当它更新时,您将获得一个构建关于重复定义的警告以提醒您这样做。

declare interface JQueryStatic {
    ajax(settings: JQueryAjaxSettings);
}

回答by Boris Yankov

You can find a fork of the jQuery definitions from the TypeScript's repo here:

您可以在此处从 TypeScript 的 repo 中找到 jQuery 定义的分支:

DefinitelyTyped

绝对类型

It contains dozens of fixes over the original, including the ajax() overload. Once the TypeScript team starts accepting pull requests, I will push the fixes there.

它包含对原始版本的数十个修复,包括 ajax() 重载。一旦 TypeScript 团队开始接受拉取请求,我就会将修复推送到那里。

On updates to TypeScript itself: it is not an alpha, but a preview. 0.8.1 version is being baked in the repos, and they have said they hope for a 2013 final version.

关于 TypeScript 本身的更新:它不是 alpha,而是预览。0.8.1 版本正在存储库中发布,他们表示希望在 2013 年发布最终版本。

回答by Martin Andersson

From DefinitelyTyped, declaration file for jQuery 1.10.x / 2.0.xis here:

从绝对类型,jQuery 1.10.x / 2.0.x 的声明文件在这里:

https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery/jquery.d.ts

https://github.com/borisyankov/DefinitelyTyped/blob/master/jquery/jquery.d.ts

..or in the raw form:

.. 或以原始形式:

https://raw.githubusercontent.com/borisyankov/DefinitelyTyped/master/jquery/jquery.d.ts

https://raw.githubusercontent.com/borisyankov/DefinitelyTyped/master/jquery/jquery.d.ts

Google Hosted Librariesdistributes (as of today) jQuery 2.1.3which is the one I prefer to use. I don't know to what extent the API has changed between 2.0 and 2.1. But if you ever discover a bug in your TypeScript application, then it might be because of a small API change in the latest version of jQuery that has not propagated to the declaration files provided above.

Google Hosted Libraries分发(截至今天)jQuery 2.1.3,这是我更喜欢使用的。我不知道 API 在 2.0 和 2.1 之间变化到什么程度。但是,如果您在 TypeScript 应用程序中发现了一个错误,那么这可能是因为最新版本的 jQuery 中的一个小的 API 更改没有传播到上面提供的声明文件中。