Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

82
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda