feat!: use const in generic for @wire
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
Nice one! I could swear I thought this wasn't possible with decorators specifically for some reason.