我试图添加' startsWith' String原型的方法。但是TypeScript编译器因为认为它已经存在而给出错误。将其命名为其他东西会很难看。我该如何正确实施?
interface String
{
startsWith(str: string): boolean;
}
if (!String.prototype.startsWith)
{
String.prototype.startsWith = function (str: string) : boolean
{
return this.indexOf(str) == 0;
};
}
构建:无法转换'(str:string)=>布尔' to' {(find:string,pos?:number,case_?:boolean):boolean; (find:string,case_?:boolean):boolean; (find:RegExp,pos?:number,case_?:boolean):boolean; (find:RegExp,case_?:boolean):boolean; (str:string):boolean; }'