I am creating a const as below.
1 const result = {
2 name : input.name,
3 events : function1(input.events),
4 status : function2(events),
5 }
But at line 4, I am getting the following error.
TS2552: Cannot find name 'events'.
How can I use the events field set at line 3 as an input parameter to function2 at line 4?
You cannot refer to a field of an object literal until after you have finished creating that object.
So to use the same value twice in an object literal, you need to have a reference to that value before hand.
There are lots of ways to "have a reference" to a value, but in this case you could simply put it into a local variable first.
For example:
const events = function1(input.events)
const result = {
name: input.name,
events, // shorthand for `events: events`
status: function2(events)
}