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

feat!: use const in generic for @wire #5073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Dec 20, 2024

Details

declare const Adapter: WireAdapterConstructor<{key: 'value'}, any, any>;
class Wired extends LightningElement {
  @wire(Adapter, {key: 'incorrect'}) prop;
}

In the example above, the wire adapter only accepts a config with key set to "value", but we have provided it with "incorrect". Despite being a runtime error, this passes type validation because the config is inferred as {key: string}. We don't know if it's the right string literal, the wrong string literal, or a reactive string ($prop) that points to a right or wrong value.

I recently learned about the const modifier in generics which solves this use case. So let's use it! Now the example above will correctly be a type error.

Does this pull request introduce a breaking change?

  • 💔 Yes, it does introduce a breaking change.

This is a breaking change for TypeScript users only.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.
  • 🔬 Yes, it does include an observable change.

GUS work item

@wjhsf wjhsf added the nomerge label Dec 20, 2024
@wjhsf wjhsf added this to the 9.0.0 milestone Dec 20, 2024
@wjhsf wjhsf requested a review from a team as a code owner December 20, 2024 18:17
@cardoso
Copy link
Contributor

cardoso commented Dec 20, 2024

Nice one! I could swear I thought this wasn't possible with decorators specifically for some reason.

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

Successfully merging this pull request may close these issues.

3 participants