Question: Typescript allows readonly class members to be initialized in the constructor, but what if data comes as a response to asynchronous request?

```
class Test { 
  readonly data;
  constructor() {
    setTimeout(() => {
        this.data = 15 // error
    });
  }
}

```

Answer: 
Depending on use case of the class in question, the data *could* be taken outside of the component and pass to the component.
I have same problem and I'm using another work-around. I pass the Promise to the property.

```
class Test { 
  readonly dataPromise: Promise<number>;
  constructor() {
    this.dataPromise = new Promise<number>((resolve) => {
      setTimeout(() => {
        resolve(15)
      }, 1000);
    })
  }
}

```

Also optionally, we can also wrap it with a getter, (although it's still async) like this: ([origin](https://medium.com/trabe/async-getters-and-setters-is-it-possible-c18759b6f7e4))

```
class Test { 
  readonly dataPromise: Promise<number>;
  constructor() {
    this.dataPromise = new Promise<number>((resolve) => {
      setTimeout(() => {
        resolve(15)
      }, 1000);
    })
  }
  // new below
  get data() {
    return ( async () => await this.dataPromise )()
  }
}

```

After writing this, I saw @Aaron Beall already suggested this 4 years ago...