【发布时间】:2022-01-16 06:04:35
【问题描述】:
这两者有什么区别?
let foo:{ [index:string] : string } = {
['hello']: 'world'
};
let bar:{ [index:string] : string } = {
'hello': 'world'
};
对于这两个值,我得到相同的结果 (world)
console.log(foo['hello'])
console.log(bar['hello'])
【问题讨论】:
-
如您所见,没有区别。这不是 TypeScript,甚至,它是一个计算出来的属性名称:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…。对于作为有效标识符的键值,也不需要引号,
{ hello: "world" }的工作原理相同。
标签: typescript index-signature