【发布时间】:2019-10-18 02:19:14
【问题描述】:
所以我学会了如何在打字稿中进行扩展:
interface Array<T> {
lastIndex(): number
}
Array.prototype.lastIndex = function (): number { return this.length - 1 }
但是如何从中获得吸气剂?例如:
interface Array<T> {
get lastIndex(): number
}
Array.prototype.lastIndex = function (): number { return this.length - 1 }
所以我可以在代码 someArray.lastIndex 中调用 is 作为 getter 吗?
我找到了这个答案,但代码不会为泛型类型编译,这样写也很丑,但也许我在打字稿中要求太多了:How to extend a typescript class with a get property?
【问题讨论】:
标签: typescript