MessageChannelType not being recognized by linter.

Issue #2118 resolved
Darrion created an issue

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)

  1. Scott Wells repo owner

    Reproduced. Man, that's a strange one. This works:

        /**
         * @param messageChannel {import('lightning/messageService').MessageChannelType} the message channel
         */
        verifyMessageChannelTypes(messageChannel) {}
    

    but this doesn't:

        /**
         * @param messageChannel {MessageChannelType} the message channel
         */
        verifyMessageChannelTypes(messageChannel) {}
    

    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 call subscribe(), 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.

  2. Scott Wells 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?

  3. Log in to comment