> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-await-to-then

[Added in v0.6.5](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.5)
## Configuration


```ts title=rslint.config.ts
import { defineConfig, promisePlugin } from '@rslint/core';

export default defineConfig([
  promisePlugin.configs.recommended,
  {
    rules: {
      'promise/prefer-await-to-then': 'error',
    },
  },
]);
```

## Rule Details

Prefer `async`/`await` over `.then()`/`.catch()`/`.finally()` for consuming Promise values.

Examples of **incorrect** code for this rule:

```javascript
function foo() {
  fetchData().then((data) => {
    process(data);
  });
}

function bar() {
  fetchData()
    .then((data) => data.json())
    .catch((err) => console.error(err));
}
```

Examples of **correct** code for this rule:

```javascript
async function foo() {
  const data = await fetchData();
  process(data);
}

async function bar() {
  try {
    const data = await fetchData();
    return await data.json();
  } catch (err) {
    console.error(err);
  }
}
```

By default, `.then()`/`.catch()`/`.finally()` inside an `await` or `yield` expression, or inside a class constructor, are not reported — those positions cannot trivially be rewritten with `await`.

Examples of **correct** code for this rule in default (non-strict) mode:

```javascript
async function foo() {
  // await wraps the .then() — not reported
  return await thing().then();
}

function* gen() {
  // yield wraps the .then() — not reported
  yield thing().then();
}

class Foo {
  constructor() {
    // inside a constructor — not reported
    doSomething.then(cb);
  }
}
```

### `strict` option

When `strict: true`, the rule also reports `.then()`/`.catch()`/`.finally()` inside `await`/`yield` expressions and constructors.

```json
{ "promise/prefer-await-to-then": ["error", { "strict": true }] }
```

```javascript
// reported with strict: true
async function foo() {
  return await thing().then();
}
```

## Original Documentation

- [eslint-plugin-promise: prefer-await-to-then](https://github.com/eslint-community/eslint-plugin-promise/blob/v7.3.0/docs/rules/prefer-await-to-then.md)
- [Source code](https://github.com/eslint-community/eslint-plugin-promise/blob/v7.3.0/rules/prefer-await-to-then.js)
