Skip to content

Unexpected no-floating-promises eslint error for MutationActionCreatorResult #4508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Rovack opened this issue Jul 11, 2024 · 7 comments
Open

Comments

@Rovack
Copy link

Rovack commented Jul 11, 2024

We have the following code:

const [mutateSomething, { isLoading }] = api.useMutateSomethingMutation();

[...]

return (
  <SomeComponent
    onSomeEvent={() => {
      mutateSomething(someArg);
    }}
  />
);

Understandably, we're getting a @typescript-eslint/no-floating-promises error.

Based on this comment, we've therefore configured our eslintrc with the following:

    '@typescript-eslint/no-floating-promises': [
      'error',
      {
        allowForKnownSafePromises: [
          { from: 'package', name: 'SafePromise', package: '@reduxjs/toolkit' },
        ],
      },
    ],

However, the eslint error isn't disappearing. Are we missing something, or does this just not work for this case for some reason?

Versions

  • "@reduxjs/toolkit": "^2.2.6"
  • "@typescript-eslint/eslint-plugin": "^7.13.1"
  • "@typescript-eslint/parser": "^7.13.1"
  • "eslint-plugin-react": "^7.34.3"
@aryaemami59
Copy link
Member

@Rovack Is this still an issue?

@Rovack
Copy link
Author

Rovack commented Jan 5, 2025

Yes, I just tried updating the dependencies and it doesn't look like anything's changed, with versions:

  • "@reduxjs/toolkit": "2.5.0"
  • "@typescript-eslint/eslint-plugin": "7.18.0"
  • "@typescript-eslint/parser": "7.18.0"
  • "eslint-plugin-react": "7.37.3"

@phryneas
Copy link
Member

phryneas commented Jan 5, 2025

Maybe you also need to add the RTKQ export?

    '@typescript-eslint/no-floating-promises': [
      'error',
      {
        allowForKnownSafePromises: [
          { from: 'package', name: 'SafePromise', package: '@reduxjs/toolkit' },
+          { from: 'package', name: 'SafePromise', package: '@reduxjs/toolkit/query' },
+          { from: 'package', name: 'SafePromise', package: '@reduxjs/toolkit/query/react' },
        ],
      },
    ],

@Rovack
Copy link
Author

Rovack commented Jan 7, 2025

Unfortunately it still doesn't work with the addition of those lines.
Not really sure how to debug why not.

@JoshuaKGoldberg
Copy link
Contributor

I'm seeing this lint report on all Promises, too. Not sure if I'm setting things up wrong or what.

Minimal reproduction in https://github.com/typescript-eslint/examples/pull/20/files:

git clone https://github.com/typescript-eslint/examples
gh pr checkout 20
npm i
cd packages/redux-toolkit-floating-promises
npm run lint
.../index.ts
  16:1  error  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  @typescript-eslint/no-floating-promises

I tried downgrading from the latest @reduxjs/[email protected] to all the versions since #4102 was merged, including down to 2.2.0. Still the lint report.

@phryneas
Copy link
Member

@JoshuaKGoldberg did you also try to add the other two packages?

@JoshuaKGoldberg
Copy link
Contributor

Ah, I did, I just neglected to check them in. Same issue. Added in typescript-eslint/examples@185fa5c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants