Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconvinient types of Channel data #1095

Open
rchl opened this issue Feb 6, 2023 · 0 comments
Open

Inconvinient types of Channel data #1095

rchl opened this issue Feb 6, 2023 · 0 comments

Comments

@rchl
Copy link

rchl commented Feb 6, 2023

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:

data: ChannelData<StreamChatGenerics> | ChannelResponse<StreamChatGenerics> | undefined;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants