1
我正在实现Typescript数组接口。我想知道是否有可能为索引定义get/set。例如:Typescript索引获取/设置
class MyClass<T> implements Array<T> {
[index: number] : T;
// ... other methods
}
有以下列方式来写一个可能性:
class MyClass<T> implements Array<T> {
get [index: number]() : T {
// implementation
}
set [index: number] (value: T) : void {
// implementation
}
// ... other methods
}
我已经在我的课了这种方法。我认为可能有直接的方式来做到这一点。 –