跳至內容

unicorn/no-thenable 正確性

此規則預設為開啟。

此規則的作用

禁止使用 then 屬性

為什麼這不好?

如果一個物件被定義為 "thenable",一旦它意外地在 await 表達式中使用,可能會導致問題

範例

javascript
async function example() {
  const foo = {
    unicorn: 1,
    then() {},
  };

  const { unicorn } = await foo;

  console.log("after"); //<- This will never execute
}

參考資料

以 MIT 許可證發佈。