Issue
I saw this TypeScript code somewhere. It compiles without any issues:
const eventName = entityName + commandName;
pubsub.publish(triggerName, { [eventName]: response });
I assumes it dynamically creates an object literal with property name called eventName. Is this assumption correct? Where in the TypeScript docs is this feature described?
Solution
That is not a typescript feature but a javascript one. It's called a computed property. Here are the docs for it.
Additionally, it does not create a property with the key eventName, but instead creates a property with a key that is the value of the variable eventName. Eg, if eventName = "foo", then {[eventName]: "bar"} is the same as {foo: "bar"}.
Answered By - CRice
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.