AngularJS: Method expression is not of Function type

馋奶兔 提交于 2019-12-23 23:06:27

问题


Having a class defined as:

angular.module('trip')
        /** @class MyClass */
        .factory('MyClass', [Factory]);

function Factory() {
   return function(){
         // fields & functions
   }
}

Then in the code I would instantiate a new object:

/**
 * @param {MyClass} MyClass
 */
function(MyClass){
   var myClass = new MyClass(); // HERE MyClass is highlighted in phpStorm
}

When calling new MyClass(); the MyClass is highlighted in phpStorm and I get this warning:

Method expression is not of Function type

What does it mean? How to get rid of it?


回答1:


WebStorm (along with other tools) understands /** @param {MyClass} MyClass */ as a declaration of an instance of MyClass. It says you can't instantiate an instance. I may only suggest to change JSDoc to /** @param {function():MyClass} MyClass */ to cease the warning. JSDoc itself doesn't offer a better way to express a factory.

Also, please take a look at https://youtrack.jetbrains.com/issue/WEB-17325.



来源:https://stackoverflow.com/questions/37297061/angularjs-method-expression-is-not-of-function-type

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