10000 [no-floating-promises] Rule proposal: Add ignore for typescript types or specific methods · Issue #4791 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
[no-floating-promises] Rule proposal: Add ignore for typescript types or specific methods #4791
Closed as not planned
@SimonSimCity

Description

@SimonSimCity

Description

Some of the functions I have in my code do return a promise, where I'm fine having them "floating around". They usually are functions whose promise already is handled in a different way, and I don't want to add .catch(() => {}) to all of them.

One example I have at hand is the package @vue/apollo-composable which lets me run a query to a GraphQL server. This function returns properties (result, error, loading) which are objects which will get the value as they arrive (vue calls it reactive). The function refetch() now returns a promise which contains the result when it arrives, but I don't need it because the reactive properties will reflect the values.

My idea was now if it would be possible to ignore those calls but not all promises ... Maybe by type (Promise<ApolloQueryResult<TResult>>) or maybe by the name of the function returning the promise.

As you see, I myself am not yet that sure about how the extra feature to the rule no-floating-promises could be implemented, but am rather open to discuss it to find a good option. If you see it not being feasible, it would be nice to know a bit more about the implementation here, to wrap my head around what would be possible instead.

Fail

new Promise(() => { });

Pass

import * as VueApolloComposable from "@vue/apollo-composable";
import gql from "graphql-tag";

const query = VueApolloComposable.useQuery<Record<string, string>, Record<string, string>>(
  gql`
    query Test() {
  test() {
    result
  }
}`,
  {},
  {}
);

// Returns a promise which is already resolved by the query.result-property
query.refetch();

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existspackage: 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

      0