Error: Type is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor

An async function can ONLY return a promise by definition – all async functions return promises. It can’t return a boolean.

That’s what TypeScript is telling you. The async function can return a promise that resolves to a boolean.

The value that you return inside your async function becomes the resolved value of the promise that the async function returns. So, the return type for your async function is a promise (that resolves to a boolean).

The caller of isLoggedIn() will have to either use .then() with it or await with it.

export class LoginService {

    async isLoggedIn(): Promise<any> {
      const r = await this.http.get('http://localhost:3000/api/user/isLoggedIn').toPromise();
      return r.body;
    }

}

Leave a Comment

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