Skip to content

Latest commit

Β 

History

History
32 lines (21 loc) Β· 1.26 KB

no-unnecessary-await.md

File metadata and controls

32 lines (21 loc) Β· 1.26 KB

no-unnecessary-await

πŸ“ Disallow awaiting non-promise values.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

The await operator should only be used on Promise values.

Awaiting a non-promise value still pauses the function for a microtask, so removing the await makes the code after it run earlier. The autofix is therefore only offered when nothing runs after the await in its function or module. The function can still settle one microtask earlier, which only matters for code that depends on the exact order of unrelated microtasks.

Examples

// ❌
await await promise;

// βœ…
await promise;
// ❌
await [promise1, promise2];

// βœ…
await Promise.allSettled([promise1, promise2]);