WebStorm 和 TypeScript 智能感知 [英] WebStorm and TypeScript intellisense
问题描述
我正在尝试为在 WebStorm 中工作的 TypeScript 获取智能感知.
I am trying to get intellisense for TypeScript working in WebStorm.
在我的测试中,我试图为 Knockout 获取它.
In my test here I am trying to get it for Knockout.
我已经添加了类型定义文件和其他必要的文件,在我的 .ts 文件的顶部添加了引用标签.
I have added the type definition file and other files necessary, added the reference tag to the top of my .ts file.
这是我设置的屏幕截图:
Here is a screenshot of my setup:
当我输入ko"时.我可以滚动列表并找到可观察的,但除此之外我没有其他智能感知.
When I type 'ko.' I can scroll through the list and find observable but other than that I get no other intellisense.
我的设置有问题吗?当我在输入 'ko.observable' 后打开一个括号时,我期望重载等是错误的吗?
Is there something wrong with my setup? Am I wrong to expect overloads and such when I open a paren after typing 'ko.observable'?
如果我改变线路
declare var ko : KnockoutState
到
declare var ko : KnockoutObservable<string>;
我收到错误
'Error:(3, 13) TS2403: 后续变量声明必须具有同类型.变量ko"必须是KnockoutStatic"类型,但这里类型为KnockoutObservable".
'Error:(3, 13) TS2403: Subsequent variable declarations must have the same type. Variable 'ko' must be of type 'KnockoutStatic', but here has type 'KnockoutObservable'.
(更新)注意:我提到上述错误只是为了表明它似乎正在读取 Knockout 的类型定义.当我把它留在 KnockoutStatic 或完全删除类型时,我仍然没有得到任何智能感知.
(UPDATE) NOTE: I mention the above error only to show that it does seem to be reading the type definition for Knockout. I still do not get any intellisense when I leave it at KnockoutStatic or remove the type out completely.
推荐答案
当我输入ko"时.我可以滚动列表并找到可观察的,但除此之外我没有其他智能感知.
When I type 'ko.' I can scroll through the list and find observable but other than that I get no other intellisense.
您需要在代码中使用它来获取智能感知.我可以看到你尝试过:
You need to use it in code to get intellisense. I can see you tried that with :
declare var ko : KnockoutObservable<string>;
这是一个无效用法......因此你得到了错误TS2403
.
Which is an invalid usage ... and hence you got the error TS2403
.
正确使用ko
:
var myObservableArray = ko.observableArray<any>(); // intellisense on `ko.`
myObservableArray.push('Some value'); // intellisense on `.p`
var anotherObservableArray = ko.observableArray([
{ name: "Bungle", type: "Bear" },
{ name: "George", type: "Hippo" },
{ name: "Zippy", type: "Unknown" }
]);
这篇关于WebStorm 和 TypeScript 智能感知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!