0

我在 common.js 文件中有以下方法。当我将“common.js”文件包含到打字稿文件中时,第一行出现编译错误。

我应该如何解决这个问题?

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, '');
});
4

1 回答 1

2

找到了。

只需将 common.js 文件移动到 common.ts 文件即可。然后在扩展“原型”的行之前添加以下代码

interface Function {
   method(name: string, func: Function): any;
}
于 2012-12-13T21:35:17.243 回答