带有Visual Studio Code中的第三方JavaScript库的Intellisense

带有Visual Studio Code中的第三方JavaScript库的Intellisense

问题描述:

我今天一直在使用Visual Studio Code,并且在获取intellisense来处理JavaScript项目中的某些代码时遇到了问题.我已经阅读了该帖子 http://www.johnpapa.net/intellisense- witha-visual-studio-code/讨论了这个问题,展示了如何将智能感知与angular结合使用.我一直在研究一些使用JavaScript库PlaygroundJS的示例项目,在这些项目中使用intellisense非常有用,因为它们通常会分解为多个文件,并且能够很好地查看定义,而不是手动跟踪它们.但是,当我查看快速操作下的可用选项时,没有看到类似的内容,在我发现的示例中:

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:

添加///对angularjs/angular.d.ts的引用

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?

是的,现在您可以为所有d.ts文件引用创建tsd.d.ts文件.将其放入您的项目一次,然后每个文件都可以引用该文件.

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.

或者使用不带文件的tsconfig.json(将其保留为未定义状态).

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

这个故事会变得更好