I have a simple class definition that is giving me an error in TypeScript.
class Container {
resolveData: (s: string) => void // not definitely initialized error!
data: Promise<string>
constructor() {
this.data = new Promise<string>(
r => this.resolveData = r
)
}
}
In this code, TypeScript is complaining about the resolveData
property not being definitely initialized.
It seems like TypeScript may not be recognizing that the callback function is synchronously executed. How can I inform TypeScript that this property is indeed initialized?