---
title: "promise/no-nesting"
description: "Disallow `then()` and `catch()` nested inside another `then()` or `catch()`"
# Generated by src/codegen/lint-rule-docs.ts. Do not edit below this line.
plugin: "promise"
aliases: []
kind: "suggestion"
category: "style"
default: "off"
fixable: "no"
typeAware: false
deprecated: false
---

A `then()` inside a `then()` adds a level of indentation for every step, and a `catch()` on the inner chain doesn't see errors from the outer one. Return the inner promise and continue the chain one level up.

A nested callback that uses a variable from the outer callback can't move up, so it isn't reported.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"promise/no-nesting" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
getUser(id).then(user => {
  return getOrders(user).then(orders => render(orders));
});
```

Not reported:

{/* good */}
```js
getUser(id)
  .then(user => getOrders(user))
  .then(orders => render(orders));
```

Here the inner callback needs `user`:

{/* good */}
```js
getUser(id).then(user => {
  return getOrders(user).then(orders => render(user, orders));
});
```
