Require Promise-like statements to be handled appropriately.
A "floating" Promise is one that is created without any code set up to handle any errors it might throw. Floating Promises can cause several issues.
// code-linter.json5
{
"rules": {
"@typescript-eslint/no-floating-promises": "error"
}
} export async function bar() {
const promise = new Promise<string>(resolve => {
resolve('value');
return 'finish';
});
await promise;
Promise.reject('value').catch(() => {
console.error('error');
});
await Promise.reject('value').finally(() => {
console.info('finally');
});
await Promise.all(['1', '2', '3'].map(x => x + '1'));
} export async function bar() {
const promise = new Promise<string>(resolve => {
resolve('value');
return 'finish';
});
promise;
Promise.reject('value').catch();
await Promise.reject('value').finally();
['1', '2', '3'].map(async x => x + '1');
} plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.