简体   繁体   English

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

[英]Enabling javascript intellisense for external libraries in Visual Studio

I updated ~/Scripts/_references.js with 我用~/Scripts/_references.js更新了~/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工作,这很棒

angular.js intellisense工作

but go a little further and it doesn't work anymore. 但是走得更远,它不再起作用了。

angular.js intellisense无法正常工作

Any ideas on why this happens or ways to make it work? 有关为什么会发生这种情况或使其发挥作用的任何想法?

Because you are using dependency injection , Visual Studio has no way to figure out what are the types of the arguments. 因为您正在使用dependency injection ,所以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.
    }
   ]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM