#Keys from variables in object literal

11 messages · Page 1 of 1 (latest)

ripe bear
#

Hi, is it possible in TS to define object literal with fields from variables, something along the lines of:

const n = 'name'
const foo = {
    `${n}`: 5
}
lament stirrup
#

Wrap the property name in []

ripe bear
#

Oh, thanks @lament stirrup !

#

Damn, I was brwosing all the docs I've found and havent found it mentioned

lament stirrup
#

And you might shorten it to

const n = 'name'
const foo = {
  [n]: 5
}
``` then
#

!resolved

cunning roostBOT
#

:warning: Only the asker can change the status of a help post

lament stirrup
#

!resolved

cunning roostBOT
#

@ripe bear
Because your issue seemed to be resolved, this post was marked as resolved by @lament stirrup.
If your issue is not resolved, you can reopen this post by running !reopen.
If you have a different question, make a new post in #1057653400046674112.

ripe bear
#

Thanks again! ❤️

lament stirrup
#

No problem