Skip to content

Bug: TypeOrValueSpecifier should allow intersection types (no-floating-promises allowForKnownSafePromises) #9303

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.4.5&fileType=.ts&code=C4TwDgpgBAyghgMwgBQE4HsC2BLAztAXijSzwgB4A7AV0wCMJUA%2BKAMigG8oB9bgG2yVgjAEKo4lACa4A-AC4ouYKkEBzKAF8A3ACgdkiAGM%2BcVNATVKh4NnSUoZ4NVSVc8JCRz4AkkMb5rW0oACgBKBXcUDC9odg5tPUdnV0jPMl9hVACbOzDdIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oDN4OBDfMwDmtYtA4BbSshTowAbXDYciaBOiQANMpVYV2SP3h8A7gDEO0ANKdTTAMr9uiAAoTps1BiUGD%2BvxVIbg95YMokbV1AnCZ%2BSUQwpxd3KRlE6L8AX0zsAF1cnJUCiBysoA&tsconfig=&tokens=false

Repro Code

type SafePromise = Promise<number> & { __linterBrands?: string };

declare function returnsSafePromiseIntersection(): SafePromise & {};

returnsSafePromiseIntersection();

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-floating-promises": [
      "error",
      {
        "allowForKnownSafePromises": [
          {
            "from": "file",
            "name": "SafePromise"
          }
        ]
      }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

Since SafePromise was marked in allowForKnownSafePromises, intersection types such as SafePromise & {} should be allowed for it.

Actual Result

The intersection type is considered a wholly new type, so is still reported on.

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator. 5:1 - 5:34

Additional Info

The seemingly-unnecessary & {} is just to make a minimum reproduction. A full example in production would be Fastify's register method returning FastifyInstance<...> & SafePromiseLike<undefined> per fastify/fastify#5506 (comment).

Note that no-floating-promises is using the shared TypeOrValueSpecifier logic. This issue only uses no-floating-promises as a canonical example for why I think we should modify the shared logic. There's no way I can tell to account for Fastify's register() returning an intersection type without fixing this.

More full repro: https://github.com/JoshuaKGoldberg/repros/tree/fastify-no-floating-promises-repros

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked 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