我想要一个承诺解析后返回一个布尔值,但打字稿给出了一个错误说承诺后打字稿返回布尔解决
A 'get' accessor must return a value.
我的代码如下所示。
get tokenValid(): boolean {
// Check if current time is past access token's expiration
this.storage.get('expires_at').then((expiresAt) => {
return Date.now() < expiresAt;
}).catch((err) => { return false });
}
此代码适用于Ionic 3 Application,存储是Ionic Storage实例。
你不能做到这一点...您可以通过只返回返回'无极'' this.storage.get ...'虽然。 –
Gerrit0
@ user2473015我通常没有在get中看到异步代码,而是异步进程设置了一个属性,get得到了... – JGFMK
而且你可能不应该为有副作用的东西使用getter。 – Bergi