Type-Problems with getting groupChannel.lastMessage in typescript

Hi everybody,

I just recently started using Sendbird, so please forgive me if I’m missing something obvious or well-know and point me in the right direction instead.

With that said, I’m having a bit of trouble with the lastMessage property of the groupChannel type in Typescript. I want to get the content of that last message. The tutorial suggests that the lastMessage property is a string, the type definition shows it being of type BaseMessage. If I console.log the groupChannel-object or even groupChannel.lastMessage I can see the .message-property. groupChannel.lastMessage.message which actually works and gives me the message content I expect, but type checks fail because .message does not (officially) exist on type BaseMessage.

Is it a bug in the SDK that .message is missing on BaseMessage or should .lastMessage actually be of another type? How could I get the content of the lastMessage (without querying the messageId specifically)?

Any help I greatly appreciated!


SDK version
@sendbird/chat”: “^4.1.0”
Vue version
“vue”: “^3.2.41”,

[Reproduction Steps]
I’m retrieving the list of channels as follows:

async function getListOfChannels(
  sb: SendbirdChat &
    ModuleNamespaces<
      [...GroupChannelModule[], MessageModule, PollModule],
      GroupChannelModule | MessageModule | PollModule
    >,
  limit = 15
) {
  const paramsList: GroupChannelListQueryParams = {
    includeEmpty: true,
    myMemberStateFilter: MyMemberStateFilter.JOINED,
    order: GroupChannelListOrder.LATEST_LAST_MESSAGE,
    limit: limit, 
  };
  const query: GroupChannelListQuery =
    sb.groupChannel.createMyGroupChannelListQuery(paramsList);

  let channels: GroupChannel[] = [];
  if (query.hasNext) {
    channels = await query.next();
  }

  return channels;
}

Then I can render the channels list the UI:

<div v-for="channel in channels" :key="channel.url">
  <div>
    {{ shortenMessage(channel.lastMessage?.message ?? "", 20) }}
  </div>
</div>

Hello @Nils_Alm,

Welcome to the Sendbird Community.

You are correct that lastMessage should be of type BaseMessage. I’ll have our documentation updated accordingly. In order to access lastMessage.message correctly, you’ll need to cast it as UserMessage which is where the .message is added.

Thank you very much Tyler, this helped me!