Skip to content

Enhancement: [no-floating-promises] Provide a built-in SafePromise type #10666

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-floating-promises

Description

Coming over from discussions such as #5844, #7008, #8404, reduxjs/redux-toolkit#4101, fastify/fastify#5498, #9869: one known user pain with @typescript-eslint/no-floating-promises is around frameworks/libraries that intentionally make "fire-and-forget" Promises. If a function's calls don't need an await by design, it's inconvenient to have the rule report on them by default.

The allowForKnownSafeCalls and allowForKnownSafePromises rule options make this better, but also require user linter configuration. For example, Redux Toolkit added a SafePromise type per allowForKnownSafePromises. Users can allowlist that type in their ESLint configs. This works but is inconvenient. Most users don't want to deeply hand-edit their ESLint configs for frameworks-specific nuances like this.

We are occasionally asked: can typescript-eslint provide its own SafePromise type that frameworks can use, and that no-floating-promises would allowlist/ignore by default?

Fail

declare function fromFramework(): Promise<void>;

await fromFramework();
// ❌ Lint report from no-floating-promises

Pass

import { SafePromise } from "@typescript-eslint/types";

declare function fromFramework(): SafePromise<void>;

await fromFramework();
// ✅ No report

Additional Info

I don't see an issue like this in our issue tracker, but know it's been suggested in at least some DMs to me. So I'm surfacing it here on behalf of users.

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin ruleevaluating community engagementwe're looking for community engagement on this issue to show that this problem is widely importantlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions