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

77
Views
typescript class with constructor calling an internal async function that initiliaze a property

Update : I'm not asking for this Async/Await Class Constructor because as I said I want to keep the async INSIDE the constructor.

I can instantiate this class without problem except I cannot get its text property just after creation. Is there a simple way without changing too much the current structure (keep the async function inside the constructor and calling it from constructor)

  class Test {
    _text: string;

    get text() {
      return this._text;
    }
    constructor() {
        (async () => {
          this._text = await _init();
          console.log(this._text);
          return this;
        })();

      async function _init() {
        return "hello";
      }
    }

  }

  let test = new Test();
  let text = test.text;
  console.log(text);
about 4 years ago · Juan Pablo Isaza
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!