phpstorm - JavaScript with function having inconsistent return points -
let's have class:
function point(x,y){ var _x=x,_y=y; this.x = function(newx){ if (typeof newx !== 'undefined') { //function x() working setter _x=newx; } else { //function x() working getter return _x; } } }
phpstorm complains function (x()) having inconsistent return points. found adding return undefined;
after _x=newx;
solves whine , code looks this.
function point(x,y){ var _x=x,_y=y; this.x = function(newx){ if (typeof newx !== 'undefined') { //function x() working setter _x=newx; return undefined; } else { //function x() working getter return _x; } } }
the question is: there way make phpstorm stop whining this?
another option annotate methods return type properly, phpstorm knows function expected return undefined
in cases.
/** * @param {number} [newx] * @returns {number|undefined} */ this.x = function(newx) { // ... }
Comments
Post a Comment