Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Method expression is not of Function type

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?

like image 929
Amio.io Avatar asked Sep 14 '26 03:09

Amio.io


1 Answers

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.

like image 180
de1mar Avatar answered Sep 16 '26 08:09

de1mar