Typescript 0.9.5使用移动功能扩展阵列原型

Typescript 0.9.5使用移动功能扩展阵列原型,typescript,Typescript,我需要使用新的原型函数move扩展本机数组,该函数基本上对数组中的项进行排序。但我在编译时出错了 Array.prototype.move = function (old_index, new_index) { while (old_index < 0) { old_index += this.length; } while (new_index < 0) { new_index += this.length; }

我需要使用新的原型函数move扩展本机数组,该函数基本上对数组中的项进行排序。但我在编译时出错了

Array.prototype.move = function (old_index, new_index) {
    while (old_index < 0) {
         old_index += this.length;
    }
    while (new_index < 0) {
        new_index += this.length;
    }
    if (new_index >= this.length) {
        var k = new_index - this.length;
        while ((k--) + 1) {
            this.push(undefined);
        }
    }
    this.splice(new_index, 0, this.splice(old_index, 1)[0]);
    //return this; // for testing purposes
};
Array.prototype.move=函数(旧索引、新索引){
而(旧指数<0){
旧_索引+=此长度;
}
而(新的_指数<0){
新的_索引+=此长度;
}
如果(新索引>=此.length){
var k=新的_指数-this.length;
而((k--)+1){
这个。推(未定义);
}
}
this.splice(新的_索引,0,this.splice(旧的_索引,1)[0]);
//返回此;//用于测试目的
};

您得到的错误可能是:

类型为“any[]”的值上不存在属性“move”

要解决这个问题,除了代码之外,还需要在数组接口上定义方法。例如:

interface Array {
    move(old_index: number, new_index: number): void;
}

注意:在TypeScript 1.0中,您必须编写接口数组

谢谢您的回答。我知道你刚才写的错误。不幸的是,我试图使用接口数组{move(old_index:number,new_index:number):void;},但仍然存在同样的问题。我仍然有这个错误。我已经安装了resharper 8.1和web essensials。@这很奇怪。确保该接口在您使用的文件
move
中被引用,或者直接在您使用的文件
move
中尝试使用该接口。