我正在尝试在TypeScript中声明一个带有动态键的字典。我对TypeScript还很陌生,这是我尝试过的:
我有一个云函数,它从路径中获取id
const messageId = context.params.messageId; // -dbaASfcaer
// Compiles but the key value is 'childId'
const payload = {
messageId : 1
}
const promise = ref.update(payload)我也试过了,但没有编译:
// Does not compile
const anotherPayload = {
`${messageId}` : 1
}发布于 2020-10-09 15:33:01
据我所知,你需要像这样的动态对象键:
const anotherPayload = {
[messageId] : 1
}https://stackoverflow.com/questions/64275698
复制相似问题