TypeScript 文件中的 JavaScript 智能感知
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12769924/
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
JavaScript Intellisense in TypeScript File
提问by daniel
Is it only possible to get intellisense in TypeScript files by referencing .tsfiles with own coded interfaces?
是否只能通过引用.ts具有自己编码接口的文件来在 TypeScript 文件中获得智能感知?
Is there a solution for existing JavaScript libraries?
是否有针对现有 JavaScript 库的解决方案?
回答by jkarpilo
You are able to get IntelliSense for other TypeScript files by using an external script reference directive at the top of your script:
您可以通过在脚本顶部使用外部脚本引用指令来获取其他 TypeScript 文件的 IntelliSense:
///<reference path="someOtherScript.ts" />
As a side note, the TypeScript IntelliSense reference directive doesn't support the tilde operator like the JavaScript reference directive does. For example, if your script is located in "~/Scripts/foo/", in JavaScript you can reference:
附带说明一下,TypeScript IntelliSense 引用指令不像 JavaScript 引用指令那样支持波浪号运算符。例如,如果您的脚本位于“~/Scripts/foo/”,则在 JavaScript 中您可以参考:
///<reference path="~/Scripts/otherScriptFile.js" />
whereas in TypeScript you have to reference relative to the current file:
而在 TypeScript 中,您必须相对于当前文件进行引用:
///<reference path="../otherScriptFile.ts" />
More info about this can be found in section 11.1.1 Source Files Dependencies of the TypeScript Spec.
更多信息可以在TypeScript Spec 的11.1.1 Source Files Dependencies 部分找到。
With regard to JavaScript IntelliSense in a TypeScript file, it currently appears to be not possible to get JavaScript reference IntelliSense.
关于 TypeScript 文件中的 JavaScript IntelliSense,目前似乎无法获得 JavaScript 引用 IntelliSense。
回答by Morten Mertner
As others before me have pointed out, you need the definition files.
正如我之前的其他人指出的那样,您需要定义文件。
The DefinitelyTyped GitHub repositoryprovides an excellent (and growing) list of definition files for a lot of popular libraries.
该DefinitelyTyped GitHub的库提供的定义文件极好的(和不断增长)名单了很多流行的库。
回答by ndm
You'll get intellisense support for every JS code (quality may vary), however the typescript specific stuff is only available when using apropriate definition files (*.d.ts).
您将获得对每个 JS 代码的智能感知支持(质量可能会有所不同),但是打字稿特定的内容仅在使用适当的定义文件 (*.d.ts) 时才可用。
You can find additional definition files in the source repository (> typings, currently only jQuery and WinJS/RT) http://typescript.codeplex.com/SourceControl/BrowseLatest
您可以在源存储库中找到其他定义文件(> 类型,目前只有 jQuery 和 WinJS/RT)http://typescript.codeplex.com/SourceControl/BrowseLatest

