我的代码中出现此ESLint错误:
function(productId:any):承诺预期在异步箭头功能的末尾返回一个值]
export const getGooglePlayPayment = async (productId) => {
await InAppBilling.close();
try {
await InAppBilling.open();
if (!await InAppBilling.isSubscribed(productId)) {
const details = await InAppBilling.subscribe(productId);
console.log('You purchased: ', details);
return details.purchaseState === PAYMENT_STATE.PurchasedSuccessfully;
}
} catch (err) {
console.log(err);
return false;
} finally {
await InAppBilling.consumePurchase(productId);
await InAppBilling.close();
}
};
有人可以帮助我解决此问题,而不必禁用ESLing规则:)
感谢
if
块中的try
语句,则不会返回任何内容。如果isSubscribed
调用为真,则应返回一些内容:export const getGooglePlayPayment = async (productId) => {
await InAppBilling.close();
try {
await InAppBilling.open();
if (!await InAppBilling.isSubscribed(productId)) {
const details = await InAppBilling.subscribe(productId);
console.log('You purchased: ', details);
return details.purchaseState === PAYMENT_STATE.PurchasedSuccessfully;
}
return 'Already subscribed';
} catch (err) {
console.log(err);
return false;
} finally {
await InAppBilling.consumePurchase(productId);
await InAppBilling.close();
}
};
((当然,将Already subscribed
替换为最有意义的内容。如果您只是想表明交易成功,也许是return true
。重要的是将其与return false
中的catch
区别开]。)