为什么`二进制操作参数类型newval与类型字符串`不兼容

时间:2015-09-22 16:09:41

标签: webstorm

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

CreateJS library

我想知道为什么

完整的模块代码:

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

1 个答案:

答案 0 :(得分:11)

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

您可以通过添加自己的JSDoc来使WebStorm停止抱怨:

if (path !== /** @type {boolean} */"") {