目录

@typescript-eslint/no-floating-promises

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.

Rule Configuration

// code-linter.json5
{
  "rules": {
    "@typescript-eslint/no-floating-promises": "error"
  }
}

Options

For details, see @typescript-eslint/no-floating-promises.

Example of Correct Code

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'));
}

Example of Incorrect Code

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');
}

Rule Set

plugin:@typescript-eslint/all

For details about how to configure Code Linter check rules, see Code Linter.