【发布时间】:2019-11-11 23:31:40
【问题描述】:
这是我的代码的一部分:
const myObj: object = {}
const propname = 'propname'
myObj[propname] = 'string'
但我得到了错误:
ERROR in path/to/file.ts(4,1)
TS7053: Element implicitly has an 'any' type because expression of type '"propname"' can't be used to index type '{}'.
Property 'propname' does not exist on type '{}'.
这里出了什么问题,我该如何解决?
【问题讨论】:
-
@TSR 哦,讽刺! :)
标签: typescript