Javascript 类型';布尔值';不可分配给类型';承诺<;布尔值>';
我正在使用inApp purchase,如果由于某种原因无法从Google或iOS app store检索到产品信息,我想将UI更改为“不可用”Javascript 类型';布尔值';不可分配给类型';承诺<;布尔值>';,javascript,typescript,async-await,promise,in-app-purchase,Javascript,Typescript,Async Await,Promise,In App Purchase,我正在使用inApp purchase,如果由于某种原因无法从Google或iOS app store检索到产品信息,我想将UI更改为“不可用” IonViewDiCenter(){ this.platform.ready().then(异步()=>{ firebase.auth().onAuthStateChanged(异步用户=>{ this.currentUser=用户; }); this.unavailable=等待此.setupProducts(); console.log('ava
IonViewDiCenter(){
this.platform.ready().then(异步()=>{
firebase.auth().onAuthStateChanged(异步用户=>{
this.currentUser=用户;
});
this.unavailable=等待此.setupProducts();
console.log('available',this.unavailable);
});
}
若要修复键入错误,您需要将函数定义为async
:
async setupProducts(): Promise<boolean> {
...
return false;
}
不要忘记
()
如果这是一个函数,而不是一个getter。作为一个函数而不是getter如何影响任何事情?你是说这可能是一个异步操作,我需要等待它完成吗?顺便提一下,您的建议很有效,但我想了解.get函数的含义。@d.Hodges如果它是这样声明的函数:async inAppPurchase():Promise
那么行将等待此操作。inAppPurchase代码>不会在应用程序购买中执行。要执行它,您需要使用()
:调用它,等待它。inAppPurchase()代码>
async setupProducts(): Promise<boolean> {
...
await this.inAppPurchase;
this.products.push(this.inAppPurchase.get(productWWHS));
this.products.push(this.inAppPurchase.get(productISA));
if (!this.products[0]) {
return true;
}
return false;
}