在Visual Studio中为外部库启用javascript intellisense

时间:2022-11-14 08:11:40

I updated ~/Scripts/_references.js with

我用〜更新了〜/ Scripts / _references.js

/// <autosync enabled="true" />
/// <reference path="angular.js" />
/// <reference path="angular-route.js" />

and in my app.js I can see some intellisense working, which is great

在我的app.js中我可以看到一些intellisense工作,这很棒

在Visual Studio中为外部库启用javascript intellisense

but go a little further and it doesn't work anymore.

但是走得更远,它不再起作用了。

在Visual Studio中为外部库启用javascript intellisense

Any ideas on why this happens or ways to make it work?

关于为什么会发生这种情况或使其发挥作用的任何想法?

2 个解决方案

#1


8  

Because you are using dependency injection, Visual Studio has no way to figure out what are the types of the arguments.

因为您正在使用依赖项注入,所以Visual Studio无法确定参数的类型。

This is a common problem with Javascript intellisense and, since Javascript does not allow for explicit type annotations, it seems that there is no clear way to work around it.

这是Javascript intellisense的常见问题,并且由于Javascript不允许显式类型注释,因此似乎没有明确的方法来解决它。

However, this can be achieved easily using Typescript (which has a VS2013 extension) and angular types where your code would look like:

但是,这可以通过使用Typescript(具有VS2013扩展名)和角度类型轻松实现,其中代码如下所示:

angular.module('example', ['ngRoute'])
  .config([ '$locationProvider',
    function ($locationProvider : ng.ILocationProvider) {

           $locationProvider. // Intellisense would work here.
    }
   ]);

#2


7  

I built a library to do just this:

我建了一个库就可以做到这一点:

https://github.com/jmbledsoe/angularjs-visualstudio-intellisense

https://github.com/jmbledsoe/angularjs-visualstudio-intellisense

#1


8  

Because you are using dependency injection, Visual Studio has no way to figure out what are the types of the arguments.

因为您正在使用依赖项注入,所以Visual Studio无法确定参数的类型。

This is a common problem with Javascript intellisense and, since Javascript does not allow for explicit type annotations, it seems that there is no clear way to work around it.

这是Javascript intellisense的常见问题,并且由于Javascript不允许显式类型注释,因此似乎没有明确的方法来解决它。

However, this can be achieved easily using Typescript (which has a VS2013 extension) and angular types where your code would look like:

但是,这可以通过使用Typescript(具有VS2013扩展名)和角度类型轻松实现,其中代码如下所示:

angular.module('example', ['ngRoute'])
  .config([ '$locationProvider',
    function ($locationProvider : ng.ILocationProvider) {

           $locationProvider. // Intellisense would work here.
    }
   ]);

#2


7  

I built a library to do just this:

我建了一个库就可以做到这一点:

https://github.com/jmbledsoe/angularjs-visualstudio-intellisense

https://github.com/jmbledsoe/angularjs-visualstudio-intellisense