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

175
Views
Is there a cleaner way to return an object from an arrow function in typescript

I'm trying to return an object from an arrow function, like this function f:

myMethod(f: data => { 
  return { someField: data.something };
});

I know that for simple types you can shrink the arrow function to just be data => data.something.

Is this possible when you are returning an object i.e. something like this:

myMethod(f: data => { someField: data.something });

That doesn't compile, I assume because the compiler thinks the { is the start of a function, not the start of an object.

Is there a syntax here which works, or should I just carry on using the longer form with the return in?

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

0

You can wrap the object with parenthesis:

myMethod((f: data) => ({ someField: data.something }));
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!