[英]VS Code intellisense for javascript not working if I am editing typescript
I was just about to take the plunge and start (incrementally) converting my node.js project to typescript when I found that VS Code (1.6.1 Mac and Windows) Intellisense is not working when (and only when) I am in a Typescript file working with an object imported from a Javascript file. 当我发现VS Code(1.6.1 Mac和Windows)Intellisense在(且仅当)我在Typescript中无法使用时,我正要尝试并开始(逐渐)将node.js项目转换为Typescript。文件与从Javascript文件导入的对象一起使用。
Javascript refs to Javascript give me Intellisense and Typescript refs to Typescript also, so I must have got the basics right, it's just that I can't mix them up. Javascript的Java引用也给了我Intellisense和TypeScript的Types引用,所以我必须具备正确的基础知识,只是我不能将它们混淆。
As I said I want to incrementally change a bunch of files and having Intellisense die on me like this is a total show stopper. 就像我说的那样,我想逐步更改一堆文件,让Intellisense像这样死在我头上,这是一个总的制止器。 Any ideas?
有任何想法吗?
OK guys I worked out what I was doing wrong. 好的,我弄清楚我做错了什么。
I was using a javascript style "require": 我正在使用JavaScript样式“ require”:
var foo = require("foo") // WRONG
var foo = require(“ foo”)//错误
Calls to foo.bar() would compile just fine but like I said no intellisense. 调用foo.bar()可以正常编译,但就像我说的没有智能感知。 When I changed my require to an import:
当我将需求更改为导入时:
import * as foo from "foo";
从“ foo”中将*作为foo导入; // RIGHT
// 对
then the intellisense showed up as soon as I later typed "foo." 然后我稍后键入“ foo”时就会出现智能提示。 - Note that this only works if you follow Tomas' advice above to add allowJS: true to your tsconfig.json.
-请注意,这仅在您按照上述Tomas的建议为您的tsconfig.json添加allowJS:true时才有效。
I think the compiler could at least have given me a warning for using the old style, if not an outright error. 我认为编译器至少应该给我使用旧样式的警告,即使不是绝对错误也是如此。 It would certainly have saved me some time.
这肯定会节省我一些时间。
Anyway Typescript here I come :-) 无论如何我来这里打字稿:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.