我想要一個承諾解析後返回一個布爾值,但打字稿給出了一個錯誤說承諾後打字稿返回布爾解決
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