Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

node.js - How to Import Intellisense files into vsCode (Visual Studio Code)

I'm not sure I understand how the intellisense works for Microsoft's new vsCode text editor. In the docs under the "Great Code Editing Experience" heading, it shows a warning under the node global variable __dir and offers a lightbulb suggestion to add a reference to a d.ts file so you can get intellisense for node:

enter image description here

I have 2 questions:

1 - How do I import DefinitelyTyped files (d.ts) directly (without editor suggesting it) or do I have to copy them from the github source and put them in a typings directory?

2 - Can I get intellisense for any library that has a typescript definition? I tried the below, but when I type in express. or when. , I don't get any intellisense. However, I do get node intellisense.

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

var when    = require('when')
  , express = require('express')
  , gulp    = require('gulp')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

UPDATE: August 2016: TSD is now depreciated. instead use https://www.npmjs.com/package/typings

npm install typings --global

OR

If using VS2015 NodeJS v1.2 released 29th July 2016 then [email protected] is installed automatically for you during first use:

Executing command 'npm install "C:PROGRAM FILES (X86)MICROSOFT VISUAL STUDIO 14.0COMMON7IDEEXTENSIONSMICROSOFTNODE.JS TOOLS FOR VISUAL STUDIO1.2TypingsAcquisitionTool"
[email protected] ..........
ode_modules
tvs-typings-acquisition-tool
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

-----Original Answer-----

There is a package manager for Typescript Definition Files. This is a community driven repository containing Typescript definitions for many popular libraries.

You can install tsd by following the instructions here.

Once you install tsd globally, you can install packages from your project root in the command line like this:

$ tsd install express --save

This will create a typings directory if one doesn't exist and adds an express directory with an express.d.ts file inside.

Screenshot

It also creates a tsd.d.ts file that contains the references to all of your tsd files. If I install a few more tsd's, here is what it looks like.

enter image description here

Now to access my tsd files, all I need to do is reference their path in at the top of my code with /// <reference path="typings/tsd.d.ts" />

enter image description here

Now I get intellisense.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...