如何在 TypeScript 中获得 jQuery 自动完成功能?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12682028/
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-08-26 11:55:26  来源:igfitidea点击:

How do I get jQuery autocompletion in TypeScript?

jquerytypescript

提问by Ryan Lundy

If I'm working in a TypeScript .ts file, what can I do to get jQuery Intellisense/autocompletion when I type the $ character?

如果我正在处理 TypeScript .ts 文件,当我输入 $ 字符时,我该怎么做才能获得 jQuery Intellisense/自动完成?

(I'm working in an ASP.NET MVC 3 project in VS 2012.)

(我在 VS 2012 中的一个 ASP.NET MVC 3 项目中工作。)

回答by mohamed hegazy

You need to add a reference to the jQuery definition at the top of your .tsfile.

您需要在.ts文件顶部添加对 jQuery 定义的引用。

/// <reference path="jquery.d.ts" />

You can find type annotations for jQuery in this sample.

您可以在此示例中找到 jQuery 的类型注释。

回答by jvitor83

Check out these type definitions for TypeScript: https://github.com/borisyankov/DefinitelyTyped#readme. They're being updated regularly and are more complete than the ones in the examples. On Nuget: http://www.nuget.org/profiles/DefinitelyTyped/

查看 TypeScript 的这些类型定义:https: //github.com/borisyankov/DefinitelyTyped#readme。它们会定期更新,并且比示例中的更完整。关于 Nuget:http://www.nuget.org/profiles/DefinitelyTyped/

回答by Ryan Cavanaugh

Checklist of things that need to be set up for this to work:

为使其工作需要设置的事项清单:

  1. Ensure the TypeScript extension is installed. Check Tools -> Extension Manager and make sure "TypeScript for Microsoft Visual Studio" extension is installed. If it isn't, run the .vsix file found in the TypeScript folder (Program Files\Microsoft SDKs\TypeScript\<version>) to install the extension.

  2. Ensure your file references the jquery.d.ts file. You should have a comment at/near the top of your file that looks like this:

  1. 确保安装了 TypeScript 扩展。检查工具 -> 扩展管理器并确保安装了“TypeScript for Microsoft Visual Studio”扩展。如果不是,请运行 TypeScript 文件夹 (Program Files\Microsoft SDKs\TypeScript\<version>) 中的 .vsix 文件以安装扩展。

  2. 确保您的文件引用了 jquery.d.ts 文件。您应该在文件顶部/附近有一条评论,如下所示:

/// <reference path="the/path/to/jquery.d.ts" />

/// <reference path="the/path/to/jquery.d.ts" />

If you need to download it, you can find the jquery.d.ts file as part of the Warship sample at http://www.typescriptlang.org/Samples/

如果您需要下载它,您可以在http://www.typescriptlang.org/Samples/找到作为 Warship 示例一部分的 jquery.d.ts 文件