WebStorm IDE 上针对绝对类型(TypeScript 类型定义)的智能感知和代码完整
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22367328/
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
intellisense and code complete for DefinitelyTyped (TypeScript type definitions) on WebStorm IDE
提问by ThiagoPXP
How can I get WebStorm IDE to give me code completion for libraries that I've downloaded.
如何让 WebStorm IDE 为我下载的库提供代码补全。
As you can see angularjs-DefinitelyTyped
and jQuery-DefinitelyTyped
have been downloaded.
如您所见angularjs-DefinitelyTyped
,jQuery-DefinitelyTyped
已下载。
Now I believe that I have to reference the definition file in my .ts files.
现在我相信我必须在我的 .ts 文件中引用定义文件。
But, where WebStorm saves the definition files so I can reference them in my code?
但是,WebStorm 在哪里保存定义文件以便我可以在我的代码中引用它们?
Thank you!
谢谢!
采纳答案by basarat
That dialog is for JavaScriptscope, not TypeScriptscope (e.g. see mocha demo http://youtu.be/4mKiGkokyx8?t=1m19s). That is, Webstorm is using TypeScript definitions to give intellisence for JavaScript.
该对话框适用于JavaScript范围,而不是TypeScript范围(例如,参见 mocha 演示http://youtu.be/4mKiGkokyx8?t=1m19s)。也就是说,Webstorm 正在使用 TypeScript 定义来为 JavaScript 提供智能。
For TypeScript itself you need to include the definitions into your project manually (https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts) and reference them like you always have.
对于 TypeScript 本身,您需要手动将定义包含到您的项目中(https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular.d.ts)并像往常一样引用它们。
回答by dug
As basarat says in his answer, you need to include the definitions manually. The easiest way to do this is with tsd. Once installed (npm install -g tsd
), navigate to the directory you want to hold the typings, and install definition files (such as angular, in the following example) like this:
正如 basarat 在他的回答中所说,您需要手动包含定义。最简单的方法是使用tsd。安装 ( npm install -g tsd
) 后,导航到要保存类型的目录,并像这样安装定义文件(例如 angular,在以下示例中):
tsd query angular --action install
or, better yet:
或者,更好的是:
tsd init
tsd query angular --save --action install
Note that you can do all this within Webstorm (alt-F12 opens a terminal window).
请注意,您可以在 Webstorm 中完成所有这些操作(alt-F12 打开一个终端窗口)。
回答by Guest
On Webstorm for mac
在 Mac 上的 Webstorm
Preferences->Languages&Frameworks->Typescript
Use tsconfig.json should be checked and you should create a tsconfig.json file which contains
使用 tsconfig.json 应该被选中,你应该创建一个 tsconfig.json 文件,其中包含
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}