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);