Intellisense with third party JavaScript libraries in Visual Studio Code

守給你的承諾、 提交于 2019-12-10 15:19:02

问题


I have been playing around with Visual Studio Code today, and have been having a problem getting intellisense to work with some of the code in a JavaScript project. I had read this post http://www.johnpapa.net/intellisense-witha-visual-studio-code/ which talks about this issue, demonstrating how you can use intellisense with angular. I've been looking at some sample projects using a JavaScript library, PlaygroundJS, and it would be very useful to use intellisense within these projects, as they are usually broken into multiple files, and it would be nice to be able to look at the definitions, rather than tracking them down manually. However, when I looked at the options available under the quick actions, I do not see anything like, which was in the example I found:

Add /// reference to angularjs/angular.d.ts

just the option to mark the variable as global. So I was wondering, is it possible to add intellisense to this library, and the other files in a project?

I did find that it was possible to add references to them at the top of each file:

/// <reference path="Global.js" />
/// <reference path="engine/Score.js"/>
/// <reference path="engine/Camera.js"/>
/// <reference path="engine/Engine.js"/>
/// <reference path="engine/EnemyManager.js"/>
/// <reference path="engine/EntityManager.js"/>

but this manual process is time consuming and unwieldy. Is there no way for it to find these references automatically?


回答1:


Yes, for now you can create a tsd.d.ts file for all of your d.ts file references. Put that in your project once, then each file can refer to that.

Or use a tsconfig.json with no files (leave it undefined).

This story will get better




回答2:


If it doesn't recognize the Angular module and suggest the d.ts import automatically, you can add the angularjs typings to your project manually.

http://definitelytyped.org describes how to import the typings into your project. I'd recommend TypeScript Definition manager as it keeps the reference comments in you code files succinct.



来源:https://stackoverflow.com/questions/29956904/intellisense-with-third-party-javascript-libraries-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!