在 es6 中,我需要承诺 return true or false 完成后

In es6 I need my promise to return true or false when done

在 es6 中我需要我的承诺 return 完成后是真还是假

这是我的尝试,但它return是一个承诺,我需要它是真还是假

return this.isUserAuthenticated()
   .then(() => this.checkIfTeacherProfileExists());  

return 部分必须为真或假。

这是 return 之一的样子:

  isUserAuthenticated = (): Promise<any> => {
    return new Promise((resolve, reject) => {  
        this.authService.checkIfLoggedIn().then((isAuthUser: boolean) => { 
            resolve(true); 
        });
    }); 
  }  

您的 return 是持有 truefalse 的承诺。所以你所要做的就是链接另一个 .then() 来保存布尔值。

return this.isUserAuthenticated()
   .then(() => this.checkIfTeacherProfileExists())
   .then(v => console.log(v)); // true or false  

关于您的评论,请参阅@FelixKling 的评论 - 您不能那样做,这不是承诺的工作方式。