# @typescript-eslint/no-floating-promises

> Require promises to be awaited, returned, or handled

A promise that nobody awaits runs on its own. If it rejects, the `try` around the call doesn't catch the error, and the code after it runs before the work is done.

A promise counts as handled if it's awaited, returned, given a `.catch()` or a second argument to `.then()`, or marked as ignored on purpose with `void`.

`bun lint --type-aware` turns this rule on in TypeScript files.

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

## Configure

Off by default. This rule needs types, so turning it on makes `bun lint` type check your code first.

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-floating-promises" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"@typescript-eslint/no-floating-promises" = ["error", {
  ignoreVoid = true,
  ignoreIIFE = false,
  checkThenables = false,
  allowForKnownSafePromises = [], # list of strings or objects
  allowForKnownSafeCalls = [], # list of strings or objects
}]
```

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

## Examples

Reported:

{/* bad */}
```ts
async function save(data: string): Promise<void> {}

function onClick() {
  save("draft");
}
```

Not reported:

{/* good */}
```ts
async function save(data: string): Promise<void> {}

async function onClick() {
  await save("draft");
}

function onBlur() {
  void save("draft");
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ignoreVoid` | `true` | Allow `void promise` as a way to say "ignored on purpose". |
| `ignoreIIFE` | `false` | Allow an async function that's called where it's written: `(async () => { ... })()`. |
| `checkThenables` | `false` | Also report objects that only have a `then` method. |
| `allowForKnownSafePromises` | `[]` | Promise types that never need handling. |
| `allowForKnownSafeCalls` | `[]` | Functions that return promises you never need to handle. |

With `ignoreVoid` set to `false`, this is reported:

{/* bad {"options": [{"ignoreVoid": false}]} */}
```ts
async function save(data: string): Promise<void> {}

void save("draft");
```

An entry in `allowForKnownSafePromises` or `allowForKnownSafeCalls` is a name, or an object that also says where the name is declared:

| Entry | What it matches |
| --- | --- |
| `"SafePromise"` | Anything with that name. |
| `{ "from": "file", "name": "SafePromise" }` | A name declared in your project. |
| `{ "from": "lib", "name": "PromiseLike" }` | A name from the built-in TypeScript types. |
| `{ "from": "package", "name": "track", "package": "analytics" }` | A name from a package. |

With `{ "from": "file", "name": "SafePromise" }` in `allowForKnownSafePromises`, this isn't reported:

{/* good {"options": [{"allowForKnownSafePromises": [{"from": "file", "name": "SafePromise"}]}]} */}
```ts
type SafePromise = Promise<void> & { neverRejects: true };

declare function log(message: string): SafePromise;

log("saved");
```

With `{ "from": "file", "name": "schedule" }` in `allowForKnownSafeCalls`, neither is this:

{/* good {"options": [{"allowForKnownSafeCalls": [{"from": "file", "name": "schedule"}]}]} */}
```ts
declare function schedule(job: () => void): Promise<void>;

schedule(() => console.log("tick"));
```
