MessageChannelType not being recognized by linter.
Issue #2118
resolved
I get this linter error/suggestion when I import a message channel and use it:
Note that 'publishLightningMessage
' is annotated with the below in its declaration:
Upon clicking the webstorm suggestion, nothing changes. Upon Ctrl-left clicking on the MessageChannelType it does take me to the correct module:
Comments (5)
-
repo owner -
repo owner Fix committed for the next build.
-
repo owner - changed status to resolved
Delivered in 2.2.2.3.
-
reporter Hi Scott - this issue has resurfaced
-
repo owner Darrion, I'm not seeing any issues. Here's an LWC ES6 class that should exercise things pretty thoroughly, and it's not raising any such JS inspection violations:
import {LightningElement, wire} from 'lwc'; import {APPLICATION_SCOPE, MessageContext, publish, subscribe, unsubscribe} from "lightning/messageService"; import SampleMessageChannel from '@salesforce/messageChannel/SampleMessageChannel__c'; export default class Issue2118 extends LightningElement { @wire(MessageContext) messageContext; verifyOtherImports() { // Message channels let subscription = subscribe( this.messageContext, SampleMessageChannel, (message) => {}, {scope: APPLICATION_SCOPE} ); unsubscribe(subscription); publish( this.messageContext, SampleMessageChannel, {recordId: ''} ); this.verifyMessageChannelTypes(SampleMessageChannel); } /** * @param messageChannel {MessageChannelType} the message channel */ verifyMessageChannelTypes(messageChannel) { publish( this.messageContext, messageChannel, {recordId: ''} ); } }
Can you please provide a concrete standalone example that reproduces the issue?
- Log in to comment
Reproduced. Man, that's a strange one. This works:
but this doesn't:
Not sure why it's not seeing those as equivalent, and not sure what I can do to coerce it to do so. What I can do, though, is suppress that false positive so that it's not shown. I've already verified that if you use the
messageChannel
parameter in that function, e.g., to callsubscribe()
, it's treated properly and doesn't result in an inspection violation.I'll first see if I can figure out some type of type equivalence, but assuming that I can't, I'll just suppress it.