我有以下代码,其中出现了WebStorm检查Binary operation argument type newVal is not compatible with type string
:
我想知道为什么
完整的模块代码:
define(function (require) {
"use strict";
var ng = require('angular');
require('../ngModule').directive('downloadFile', ['$parse', 'auth.authService', function ($parse, authService) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var getter = $parse(attrs.downloadFile);
scope.$watch(getter, function (path) {
if (path !== "") {
var form = document.createElement("form");
var element1 = document.createElement("input");
var element2 = document.createElement("input");
form.method = "POST";
form.action = path;
element1.value = authService.getToken();
element1.name = "Authorization";
form.appendChild(element1);
element.append(form);
form.submit();
element.empty();
}
});
}
};
}]);
});
答案 0 :(得分:11)
AngularJS的JSDoc定义使WebStorm认为path
参数是一个布尔值。
您可以通过添加自己的JSDoc来使WebStorm停止抱怨:
if (path !== /** @type {boolean} */"") {