3
lorentz
4y

JS has
dynamic object literal keys
String object literal keys
Why aren't template literal keys allowed, and _why_ isn't there a proper error message for them?

Comments
  • 4
    You can still use template literals

    {
    [`foo_${bar}`]: biz
    }
  • 2
    You can use template literals as object keys.
    I don't know what error you got, but chances are, an interpolation in your template literal is wrong, or the resulting data doesn't play nice as an object key.
  • 0
    @Berkmann18 I just did
    @highlight
    {
    `Content-Type`: `application/json`
    }
  • 0
    but it broke either Typescript or VSCode.
  • 1
    @homo-lorens wrong syntax.
  • 1
    @homo-lorens Don't confuse TypeScript with javascript. They're not the same thing.
  • 3
    @homo-lorens That's not a correct syntax, AFAIK; it should have the [] encapsulating the dynamic key.
    And why would you use backticks if you're not interpolating anything?
Add Comment