hewong
December 6, 2021, 9:40am
1
I’m trying to use create a GroupChannelCollection
following the documentation like this:
sb.GroupChannel.createGroupChannelCollection()
.setOrder(sb.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE)
.setFilter(groupChannelFilter)
.build();
but I got a TypeScript error complaining that string
is not assignable to GroupChannelOrder
Seems like there’s some problem in the type definition file:
type GroupChannelOrder = {
LATEST_LAST_MESSAGE: 'latest_last_message',
CHRONOLOGICAL: 'chronological',
CHANNEL_NAME_ALPHABETICAL: 'channel_name_alphabetical',
};
This type expects me to pass in this exact object:
.setOrder({ LATEST_LAST_MESSAGE: 'latest_last_message', CHRONOLOGICAL: 'chronological', CHANNEL_NAME_ALPHABETICAL: 'channel_name_alphabetical' })
Also, I believe it doesn’t happen to just GroupChannelOrder
…
Hi hewong,
There should be no error when following the documentation below.
What is the type definition file you mentioned? Where did you find them?
hewong
December 7, 2021, 8:16am
3
Yes, that’s the documentation that I followed.
This is the type definition file that I mentioned: SendBird.d.ts (line 85)
Here’s a screenshot of the error when I followed exactly the documentation:
And if I put in a string:
The current GroupChannelOrder
requires all properties to be present, which is an object.
What should be expected by .setOrder
is a string, and to solve this issue, the type declaration should be something like this:
type GroupChannelOrder = 'latest_last_message' | 'chronological' | 'channel_name_alphabetical';
Could you try to use it like this?
.setOrder(sb.GroupChannelCollection.GroupChannelOrder.ORDER_LATEST_LAST_MESSAGE)
hewong
December 7, 2021, 8:53am
5
Isn’t that what I did as mentioned in my topic and reply? That is also exactly what is documented.
If you’re thinking about the this
keyword that’s because I’m using a class component.
It’s still the same even if I don’t put it in a class component.
I really hope you did read what I said, please take a look at the type definition file, any TypeScript programmer should know what I mean…
Thank you
Really sorry. Let me check with JS engineer.
My teammate suggested a workaround as below including a comment.
It’s like if you in typescript declare the variable as const sort :any = ...
If you pass the string, it’s not the same as any
const order = sb.GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE;
var groupChannelCollection = sb.GroupChannel.createGroupChannelCollection()
.setOrder(order)
.setFilter(groupChannelFilter)
.build();
Once getting the technical details, I will share with you.
hewong
December 7, 2021, 10:21am
8
Thanks, would give it a try
This issue will be fixed soon. Sorry to make you confusing.
hewong
December 7, 2021, 1:14pm
10
No worries, thanks for the reply!
Hi @hewong this has been fixed in 3.1.4 version of the Sendbird SDK.
Update to resolve this by running:
npm i sendbird@3.1.4