Reputation: 732
I'm testing the new code editor from Microsoft : Visual Studio Code.
I'm under Windows 7 and i'm trying this example : https://code.visualstudio.com/Docs/nodejs
But when i try to add /// <reference path="/typings/node/node.d.ts"/>
like it is said in the example. It does'nt work. The file is never downloaded and i don't know where i can find it.
Is someone knows how to fix that ? Is it a bug or the problem come from my machine ?
Upvotes: 5
Views: 13943
Reputation: 9564
As @HenryLi mentioned, you need to get a file with type definitions for Node. However TSD has been deprecated for quite a while now. Worry not, however! Now the type definitions are managed directly by Microsoft and bundled right through npm
!
To solve your problem, it's enough to run this command:
npm install --save -g @types/node
Upvotes: 0
Reputation: 1
(Edit: VS Code needs me to open a directory, and not a single file to let intellisense work well)
Same problem for me.
This does not work:
Add /// reference to 'node/node.d.ts'
Nothing happens...
But this does work, VS Code is responding. (Edit: stops the warning, but no auto-completion this way):
Mark '__dirname' as global
Upvotes: -2
Reputation: 261
TSD is TypeScript Definition, while TypeScript is a typed superset of JavaScript from Microsoft that compiles to plain JavaScript. You don't need to understand these if you just want to use VSCode to develop common JavaScript-based node.js projects like me.
To solve your problem, I think a better way is to install the TSD package manager as a global module. This will enable you to use the command tsd globally.
npm install tsd@next -g
Then go to the root folder of your project, and type
tsd install node
This will automatically create a folder 'typings/node' with a .ts file named 'node.d'.
If you also need IntelliSense for third party modules like express.js or async.js, you can just add them by yourself
tsd install express
Just like 'npm' which you already be familiar with is the package manager for node.js, 'tsd' is the package manager for TypeScript Definition (but not for TypeScript itself)
There's a list here showing the available repositories.
Once you download all the .tsd files into the 'typings' folder, you still have to manually put these special comments at the beginning of each .js files to help VSCode look up the definitions for node and express, so now VSCode knows the API details of the classes and functions.
/// <reference path="typings/node/node.d.ts"/>
/// <reference path="typings/express/express.d.ts"/>
Upvotes: 24
Reputation: 2701
I had the same problem with angular and this is how I got it to work for me: It looks like the problem was that VSCode failed to download the file and create the directories. I googled angular.d.ts and found it on GitHub - DefinitelyTyped
I created "typings/angularj/" folders and added the file and now intellisense is working for angular :)
So just grab the "node.d.ts" file instead of from DefinitelyTyped and it should work for you as well.
Upvotes: 0
Reputation: 195
I just tried last night and it worked fine.
You shouldn't put the reference by yourself. You should let VS Code do it for you by pressing "Ctrl + ." (thats the dot key you should press) on the marked __dirname and choosing the option for the TypeScript Definition file as said on the website.
VS Code will create the directories structure under your project folder, download the file and add the reference to your app.js express application.
Upvotes: 2