gpt4 book ai didi

webstorm - 为什么会出现 `binary operation argument type newval is not compatible with type string`

转载 作者:行者123 更新时间:2023-12-03 10:43:26 24 4
gpt4 key购买 nike

我有以下代码,其中包含 WebStorm 检查 Binary operation argument type newVal is not compatible with type string出现:

enter image description here

我想知道为什么

完整的模块代码:

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();
}
});
}
};
}]);
});

最佳答案

AngularJS 的 JSDoc 定义使 WebStorm 认为 path参数是一个 bool 值。

您可以通过添加自己的 JSDoc 来让 WebStorm 停止提示:
if (path !== /** @type {boolean} */"") {

关于webstorm - 为什么会出现 `binary operation argument type newval is not compatible with type string`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32721724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com