跳转到内容

useAwaitThenable

此内容尚不支持你的语言。

biome.json
{
"linter": {
"rules": {
"nursery": {
"useAwaitThenable": "error"
}
}
}
}

Enforce that await is only used on Promise values.

invalid-primitive.js
await 'value';
/invalid-primitive.js:1:1 lint/nursery/useAwaitThenable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

`await` used on a non-Promise value.

> 1 │ await ‘value’;
^^^^^^^^^^^^^
2 │

This may happen if you accidentally used `await` on a synchronous value.

Please ensure the value is not a custom “thenable” implementation before removing the `await`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables

invalid-function-call.js
const createValue = () => 'value';
await createValue();
/invalid-function-call.js:2:1 lint/nursery/useAwaitThenable ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

`await` used on a non-Promise value.

1 │ const createValue = () => ‘value’;
> 2 │ await createValue();
^^^^^^^^^^^^^^^^^^^
3 │

This may happen if you accidentally used `await` on a synchronous value.

Please ensure the value is not a custom “thenable” implementation before removing the `await`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables

valid-examples.js
await Promise.resolve('value');
const createValue = async () => 'value';
await createValue();