Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
How to use a field in TypeScript object as a value of another field?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!