简体   繁体   中英

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.

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.

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. Any ideas?

OK guys I worked out what I was doing wrong.

I was using a javascript style "require":

var foo = require("foo") // WRONG

Calls to foo.bar() would compile just fine but like I said no intellisense. When I changed my require to an import:

import * as foo from "foo"; // RIGHT

then the intellisense showed up as soon as I later typed "foo." - Note that this only works if you follow Tomas' advice above to add allowJS: true to your tsconfig.json.

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 :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM