mark andrew mark andrew - 1 month ago 12
TypeScript Question

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?

Answer

OK guys I worked out what I was doing wrong.

I was using a javascript style "require":

var foo = require("foo") // W R O N G

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"; // R I G H T

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