Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code download node.d.ts

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 ?

like image 574
Sachacr Avatar asked Apr 30 '15 09:04

Sachacr


People also ask

How do I download npm in Visual Studio?

Use the search box to find the npm file, choose the npm Configuration File, use the default name, and click Add. If you don't see the npm Configuration File listed, Node. js development tools are not installed. You can use the Visual Studio Installer to add the Node.


2 Answers

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.

http://definitelytyped.org/tsd/

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"/>
like image 104
Henry Li Avatar answered Oct 22 '22 07:10

Henry Li


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.

like image 2
Pedro Costa Avatar answered Oct 22 '22 07:10

Pedro Costa