Skip to content
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

False positive in @lwc/lwc/valid-graphql-wire-adapter-callback-parameter if a class method signature expects an object with an error property #160

Open
amurashincertinia opened this issue Jul 11, 2024 · 0 comments

Comments

@amurashincertinia
Copy link

There is a bug in @lwc/lwc/valid-graphql-wire-adapter-callback-parameter which falsely reports undecorated class methods if their argument is an object with an error property like in this example:

class C {
    f({ error }) {
        return error;
    }
}

The root cause of the issue is that the graphQlDecorator const is initialised as false if decorators === undefined:

// Check that the @wire decorator is using graphql
const graphQlDecorator =
    decorators !== undefined && // this yields `false`
    decorators.find((decorator) => { // this does not run

Which satisfies the condition for verification:

// Verify that the method definition is using 'errors' not 'error
if (graphQlDecorator !== undefined) { // this evaluates to `true`

Replacing the decorators !== undefined check with an optional chaining operator fixes the issue.

const graphQlDecorator = decorators?.find((decorator) => { // happy days!

An alternative solution without optional chaining:

const graphQlDecorator = (decorators || []).find((decorator) => {
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

1 participant