Typescript 字符串原型在 webstorm 中显示错误 IDE

Typescript string prototype show error in webstorm IDE

我给String定义了如下格式化函数。 这工作正常,但问题是 webstorm 将 "String.prototype.format" 标记为红色。 我怎样才能抑制错误?

interface String {
    format(variables:Array<string>):string
}

String.prototype.format = (variables:Array<string>):string => {
    return this.replace(/%(\d+)/g, function(_,m) {
        return variables[--m];
    });
};

谢谢

我找到了一个解决方法,结果是:

interface String {
    format(variables:Array<string>):string
}

if (!String.hasOwnProperty("format")) {
    String.prototype["format"] = function (variables:Array<string>) : string   {
        return this.replace(/%(\d+)/g, function(_,m) {
            return variables[--m];
        });
    };
}

这是一个错误。参见 WEB-14302

该问题应在下一个 WebStorm 11 EAP 中修复。