Visual Studio Code Intellisense not working for Javascript

Viewed 73130

I am using Visual Studio Code (VSC) 0.10.11 on Windows and Mac. For the purpose of this question I have this small JavaScript snippet:

'use strict';

const os = require('os');
console.log(os.homedir());

I followed John Papa on Visual Studio Code (Blog entry and Pluralsight Visual Studio Code JavaScript Intellisense - for those who have an account) and therefore I would expect that VSC provides Intellisense and Quick fix options when typings are available.

In the snippet above VSC recognizes console and log() (I use hoover, but it is the same with Intellisense):

console log

but not os and homedir():

os homedir

But all 4 typings are available in typings/main/ambient/node/index.d.ts. I know that the difference is the require in the case of os, but in John Papa's video course VSC also provided IntelliSense for required modules. A difference is that John Papa used tsd while I am using typings.

So my questions are

  • how can I enable Intellisense for all known typings?
  • what do I have to do that VSC offers me Quick fix (green line under moduls with missing typings)?
4 Answers

There is a built-in extension called TypeScript and JavaScript Language Features (vscode.typescript-language-features) that is disabled.

In order to enable it, open Extensions panel, search for "@built-in JavaScript", and enable the required extension.

Now you should be able to use the autocomplete feature.

I experienced this on global "process" object. Vscode enabled intellisense for process object, only if I add any "require" statements to the file.

So if there is not any other require statements, you can add

const process = require('process');

in the beginning of your script to get intellisense.

Well, after 4 hr's googling finally, I decided to uninstall nodejs, npm, and typescript then install all of them again. The previous time I installed them using nvm but this time I decided not to use nvm just install them from node source since I am using Ubuntu I executed bellow commands, for windows or mac just install them without any package or version manager.

curl https://deb.nodesource.com/gpgkey/nodesource.gpg.key | sudo apt-key add -
sudo apt-add-repository "deb https://deb.nodesource.com/node_7.x $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get install nodejs

above command installed both nodejs and npm, after then to install typescript I ran bellow command

sudo npm install --global typescript

I updated my VSCode to the newest version.

enter image description here

Then in the bottom right of my VSCode I clicked on javascript to change the language mode, I wrote 'type' on the search bar and select typescript as my new selected language mode...........BINGO

enter image description here

Related