Support computed properties in Json
, Map
literals
#7157
Labels
✨ enhancement
New feature or request
📐 language-design
Language architecture
needs-discussion
Further discussion is needed prior to impl
Use Case
If you are initializing a new
Map
orJson
object and one if its keys is a variable (not a fixed string), then it's not easy to accomplish today. One way to do it is to create aMutJson
object, set an item, and then if want it to be immutable, to useJson.deepCopy
, but it's awkward and is inefficient because of the copying involved:Proposed Solution
Support computed properties, similar to JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#computed_property_names
In Wing this might look like:
An alternative design could be to change Wing's object literal syntax so keys that aren't surrounded by quotes have to refer to variables:
But since Wing interoperates with TypeScript, I suspect this would confuse folks and add friction for people switching to Wing, so I recommend against it.
Implementation Notes
No response
Component
Language Design, Compiler
Community Notes
The text was updated successfully, but these errors were encountered: