Enabling javascript intellisense for external libraries in Visual Studio

耗尽温柔 提交于 2019-12-12 08:22:03

问题


I updated ~/Scripts/_references.js with

/// <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

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

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


回答1:


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

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.

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

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

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



回答2:


I built a library to do just this:

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



来源:https://stackoverflow.com/questions/20569173/enabling-javascript-intellisense-for-external-libraries-in-visual-studio

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