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

Remove misleading warning when using @wire on a getter or a setter #4428

Open
wjhsf opened this issue Jul 31, 2024 · 1 comment
Open

Remove misleading warning when using @wire on a getter or a setter #4428

wjhsf opened this issue Jul 31, 2024 · 1 comment

Comments

@wjhsf
Copy link
Contributor

wjhsf commented Jul 31, 2024

class extends LightningElement {
  @wire(getData, {id: 1}) get dataProp() {}
  @wire(getData, {id: 2}) set otherProp(v) {}
}

Currently, using @wire on a getter or a setter successfully compiles, but it fails at runtime with "Error: [LWC error]: Invalid @wire dataProp field. Found a duplicate accessor with the same name." To prevent deploying faulty code, this error should be caught at compile time.

Currently, using @wire on a getter or a setter works, but it logs a misleading error at runtime, "Error: [LWC error]: Invalid @wire dataProp field. Found a duplicate accessor with the same name." This error should not be logged.

@nolanlawson
Copy link
Collaborator

This is actually subtle. You can use an @wire with a getter/setter in the following ways:

In all three cases, the wire works as expected but an error is logged:

Invalid @wire value field. Found a duplicate accessor with the same name.

Since this is behavior we support (and I don't see any reason not to support it – a getter/setter is roughly the same as a class property), I would propose we don't remove it and instead get rid of the error-logging.

Based on the tests for the error message BTW, it looks like the intention was to prevent truly egregious mistakes like this one:

expect(() => {
class DuplicateProperty extends LightningElement {
foo = 'observed';
// eslint-disable-next-line no-dupe-class-members
@wire(adapter) foo = 'wired';
render() {
return duplicatePropertyTemplate;
}
}
Ctor = DuplicateProperty;
}).toLogErrorDev(
/Invalid observed foo field\. Found a duplicate accessor with the same name\./
);

@wjhsf wjhsf changed the title Throw compiler error when using @wire on a getter or a setter Remove misleading warning when using @wire on a getter or a setter Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants