Reputation: 495
I defined the following format function to String. This works OK, but the problem is that webstorm is marking the "String.prototype.format" in red. How can I suppress the error?
interface String {
format(variables:Array<string>):string
}
String.prototype.format = (variables:Array<string>):string => {
return this.replace(/%(\d+)/g, function(_,m) {
return variables[--m];
});
};
Thanks
Upvotes: 2
Views: 278
Reputation: 8136
It is a bug. See WEB-14302
The problem should be fixed in the next WebStorm 11 EAP.
Upvotes: 0
Reputation: 495
I found a workaround for this, I ended up with this:
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];
});
};
}
Upvotes: 1