stream-chat-js icon indicating copy to clipboard operation
stream-chat-js copied to clipboard

Inconvinient types of Channel `data`

Open rchl opened this issue 2 years ago • 0 comments

The fact that channel data can be either ChannelData or ChannelResponse can be quite inconvenient since then it's not clear to typescript whether given property can exist on the data object or not and it can result in properties being typed as unknown. So in a code like:

    const channels = await chatClient.queryChannels({
        type: 'messaging',
        members: { $in: ['13006'] },
    });
    const channel = channels[0];
    console.info(channel.data?.created_by.id);

there will be an error like the one below when trying to access created_by property:

Screenshot 2023-02-06 at 14 27 05

There is probably a good reason for the type to be either but it's not working very well when trying to access data properties.

There could perhaps exist another method that returns data of the type ChannelResponse. Even if it's the same data but just type-casted.

I know that I could type cast or similar to work around that but it's not ideal...

This is the relevant code in stream-chat:

https://github.com/GetStream/stream-chat-js/blob/b7936ed71c42a68055d263f16e2d2fbc4638e993/src/channel.ts#L66

rchl avatar Feb 06 '23 13:02 rchl