跳到內容

promise/prefer-await-to-then 風格

功能說明

讀取 Promise 值時,偏好使用 await 而非 then()/catch()/finally()

為何不好?

Async/await 語法可以被認為更易讀。

範例

此規則的錯誤程式碼範例

javascript
function foo() {
  hey.then((x) => {});
}

此規則的正確程式碼範例

javascript
async function hi() {
  await thing();
}

參考資料

以 MIT 授權發布。