为什么会出现`binary operation argument type newval is not compatible with type string` [英] Why does `binary operation argument type newval is not compatible with type string` appear

查看:40
本文介绍了为什么会出现`binary operation argument type newval is not compatible with type string`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,其中 WebStorm 检查 二元运算参数类型 newVal 与类型字符串不兼容 出现:

I have the following code and inside of it the WebStorm inspection Binary operation argument type newVal is not compatible with type string appears:

我想知道为什么

完整模块代码:

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 参数是一个布尔值.

AngularJS's JSDoc definition makes WebStorm think the path argument is a boolean.

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

You can make WebStorm stop complaining by adding your own JSDoc:

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

这篇关于为什么会出现`binary operation argument type newval is not compatible with type string`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆