在 Typescript 中,您只需这样做:
class Test {
[key: string]: whatever
}
它允许您像这样访问计算的属性名称......
class Test {
getProp(key) {
return this[key]
}
}
...没有收到Element implicitly has an 'any' type because type 'Test' has no index signature.
我不知道如何用 JSDoc 完成等效操作。有人对此有任何运气吗?