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

标签 webstorm

我有以下代码,其中包含 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/

相关文章:

typescript - Webstorm:如何从 typescript 项目中的代码完成中排除 javascript

angular - @Component 突然无法识别指令

javascript - 我可以在 WebStorm 中添加 "virtual"文件夹来轻松添加和隐藏配置文件吗?或者是否有一个功能可以轻松切换特定文件的可见性?

intellij-idea - 如何将 WebStorm 与 Vue.js 集成

node.js - 即使在 Webstorm 2018.3 中进行 Babel 配置后,Spread Operator 也会抛出 SyntaxError

linux - WebStorm 找不到文件,在终端打开 WebStorm

intellij-idea - 是否可以使用实时模板作为文件模板?

javascript - 使用 Webstorm 服务器提供 PHP 服务

intellij-idea - 如何从根 url 运行应用程序 (localhost :port/) instead of (localhost:port/path/index. html)

javascript - WebStorm/PhpStorm 对 jsx 中的 react 属性的警告,如 className