简中文档

no-await-in-sync-fn

NOTE: this rule is part of the 推荐 rule set.
Enable full set in deno.json:
{
  "lint": {
    "rules": {
      "tags": ["推荐"]
    }
  }
}
Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the include or exclude array in deno.json:
{
  "lint": {
    "rules": {
      "include": ["no-await-in-sync-fn"],
      "exclude": ["no-await-in-sync-fn"]
    }
  }
}

禁止在非异步函数中使用 await 关键字。

在非异步函数中使用 await 关键字是语法错误。要在函数内部使用 await,必须通过 async 关键字将该函数标记为异步。

无效:

function foo() {
  await bar();
}

const fooFn = function foo() {
  await bar();
};

const fooFn = () => {
  await bar();
};

有效:

async function foo() {
  await bar();
}

const fooFn = async function foo() {
  await bar();
};

const fooFn = async () => {
  await bar();
};

你找到了你需要的东西吗?

编辑此页面
隐私政策