Get a value from a Promise Typescript

How do I unwrap/yield the value inside that promise

You can do it with async/await.Don’t be fooled into thinking that you just went from async to sync, async await it is just a wrapper around .then.

functionA(): Promise<string> {
   // api call returns Promise<string>
}

async functionB(): Promise<string> {
   const value = await this.functionA() // how to unwrap the value inside this  promise
   return value;
}

Further

  • TypeScript Deep Dive docs

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)