Visual Studio Code download node.d.ts

I am testing a new code editor from Microsoft: Visual Studio Code.

I am on Windows 7 and I am trying this example: https://code.visualstudio.com/Docs/nodejs

But when I try to add /// <reference path="/typings/node/node.d.ts"/>

as stated in the example. He does not work. The file never loads and I don't know where to find it.

Does anyone know how to fix this? Is this a bug or a problem with my machine?

+3


source to share


5 answers


TSD stands for TypeScript Definition, and TypeScript is Microsoft's typed JavaScript supercomplex that compiles to plain JavaScript. You don't need to understand them if you just want to use VSCode to develop generic JavaScript-based node.js projects like me.

To solve your problem, I believe the best way is to set TSD package manager as a global module. This will allow you to use the tsd command 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 "typings / node" folder 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 yourself



tsd install express

      

Like "npm" you are already familiar with, this is the package manager for node.js, 'tsd' is the package manager for TypeScript Definition (but not for TypeScript itself)

Here is a list of available repositories.

http://definitelytyped.org/tsd/

Once you load all the .tsd files into the "typings" folder, you still have to manually put these special comments at the beginning of each .js file to help VSCode find the definitions for the node and express, so now VSCode knows the API information about classes and functions ...

/// <reference path="typings/node/node.d.ts"/>
/// <reference path="typings/express/express.d.ts"/>

      

+24


source


I just tried it last night and everything worked out fine.

You don't have to link yourself. You have to let VS Code do this for you by pressing Ctrl +. (this is the dotted key that you have to press) on the marked __dir name and select the option for the TypeScript definition file as stated on the website.



VS Code will create a directory structure in your project folder, download the file, and add a link to your app.js express app.

+2


source


I had the same problem with angular and this is how I got it working for me: it looks like the problem is that VSCode was unable to upload the file and create directories. I googled angular.d.ts and found it on GitHub - Definitely Type >

I created "typings / angularj /" folders and added a file and now intellisense works for angular :)

So just grab the node.d.ts file and not from DefinitelyTyped and it will work for you too.

0


source


As @HenryLi mentioned, you need to get the type definitions file for Node. However, TSD has long been outdated. Don't worry, though! The type definitions are now managed directly by Microsoft and inserted right through npm

!

To solve your problem, just run this command :

npm install --save -g @types/node

      

0


source


(Edit: VS Code I need to open a directory, not a single file for intellisense to work well)

Same problem for me.

This does not work:

Add /// link to 'node / node.d.ts'

Nothing happens...

enter image description here

But it does work, VS Code answers. (Edit: stops the warning, but autocomplete is not done this way):

Mark '__dirname' global

enter image description here

-2


source







All Articles