简体   繁体   English

如果我正在编辑打字稿,则javascript的VS Code intellisense无法正常工作

[英]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.

相关问题 我正在使用 Javascript,但 VS Code 给了我 typescript 智能感知。 我如何解决它? - I'm working with Javascript, but VS Code gives me typescript intellisense. How do I fix it? JavaScript 的 VS Code Intellisense 不起作用? - VS Code Intellisense for JavaScript is not working? VS Code 中 Javascript 的 Intellisense 自动完成功能不起作用 - Intellisense autocompletion for Javascript in VS Code not working VS代码为任何项目两次显示javascript和打字稿帮助(intellisense) - VS code is displaying javascript and typescript help (intellisense) twice for any item VS 2010 Javascript Intellisense无法正常工作 - VS 2010 Javascript Intellisense not working VS JavaScript IntelliSense无法正常工作 - VS JavaScript IntelliSense not working as expected VS 代码自动完成/智能感知不工作 - VS Code autocomplete/intellisense not working TypeScript IntelliSense无法在VS2012中按预期方式工作 - TypeScript IntelliSense not working as expected in VS2012 VS Code智能感知与TypeScript编译不匹配 - Mismatch between VS Code intellisense and TypeScript compilation 为什么VS Code javascript intellisense取决于我打开的文件? - Why is VS Code javascript intellisense dependent on the files I have open?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM