close

promise-function-async

Configuration

rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/promise-function-async': 'error',
    },
  },
]);

Rule Details

Require any function or method that returns a Promise to be marked async. Ensures that each function is only capable of either returning a rejected promise or throwing an Error object. In contrast, non-async Promise-returning functions are technically capable of either. Code that handles both rejected promises and thrown errors simultaneously is often overly complex and hard to maintain.

Examples of incorrect code for this rule:

function foo(): Promise<string> {
  return Promise.resolve('value');
}
const bar = (): Promise<number> => Promise.resolve(42);
class Baz {
  method(): Promise<void> {
    return Promise.resolve();
  }
}

Examples of correct code for this rule:

async function foo(): Promise<string> {
  return 'value';
}
const bar = async (): Promise<number> => 42;
class Baz {
  async method(): Promise<void> {}
}

Original Documentation