Typescript 对Function.prototype进行过度编码时出现编译错误
我在common.js文件中有以下方法。当我将“common.js”文件包含到typescript文件中时,在第一行出现编译错误 我应该如何解决这个问题Typescript 对Function.prototype进行过度编码时出现编译错误,typescript,Typescript,我在common.js文件中有以下方法。当我将“common.js”文件包含到typescript文件中时,在第一行出现编译错误 我应该如何解决这个问题 Function.prototype.method = function (name, func) { ///<summary> ///Create a new method if it not ready exists ///</summary> if (!this.prototype[
Function.prototype.method = function (name, func) {
///<summary>
///Create a new method if it not ready exists
///</summary>
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
String.method('trim', function () {
return this.replace(/^\s|\s+$/g, '');
});
Function.prototype.method=函数(名称,func){
///
///如果未准备好,请创建新方法
///
如果(!this.prototype[name]){
this.prototype[name]=func;
归还这个;
}
};
方法('trim',函数(){
返回此值。替换(/^\s |\s+$/g');
});
找到了它
只需将common.js文件移动到common.ts文件。然后在扩展“prototype”的行之前添加以下代码
interface Function {
method(name: string, func: Function): any;
}