Urara-Blog/node_modules/.pnpm-store/v3/files/d9/bf93cc826aadaaad199a66d8f8494ac97aeed3a7ef5e114dea65b24f0b933d45851b7379324cc7c60fccc982898486b4a8b27cfca739cc0da97d25ddacb149
2022-08-14 01:14:53 +08:00

52 lines
1.1 KiB
Text

---
description: 'Disallow awaiting a value that is not a Thenable.'
---
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/await-thenable** for documentation.
This rule disallows awaiting a value that is not a "Thenable" (an object which has `then` method, such as a Promise).
While it is valid JavaScript to await a non-`Promise`-like value (it will resolve immediately), this pattern is often a programmer error, such as forgetting to add parenthesis to call a function that returns a Promise.
## Rule Details
Examples of code for this rule:
<!--tabs-->
### ❌ Incorrect
```ts
await 'value';
const createValue = () => 'value';
await createValue();
```
### ✅ Correct
```ts
await Promise.resolve('value');
const createValue = async () => 'value';
await createValue();
```
## Options
```jsonc
// .eslintrc.json
{
"rules": {
"@typescript-eslint/await-thenable": "error"
}
}
```
This rule is not configurable.
## When Not To Use It
If you want to allow code to `await` non-Promise values.
This is generally not preferred, but can sometimes be useful for visual consistency.