stream-chat-react-native icon indicating copy to clipboard operation
stream-chat-react-native copied to clipboard

UserResponse<LocalUserType> is not assignable to type 'UserResponse<LocalUserType & OwnUserBase<LocalChannelType, string, LocalUserType>>'

Open skam22 opened this issue 3 years ago • 9 comments

Describe the bug Typescript 4.4.4 error with v3.10.2:

Type 'UserResponse<LocalUserType>' is missing the following properties from type 'OwnUserBase<LocalChannelType, string, LocalUserType>': channel_mutes, devices, mutes, total_unread_count, and 2 more.

Dev environment info (please complete/provide the following information):

  • Package version stream-chat-react-native 3.10.2
  • react-native
  • Device/Emulator (iOS & simulator) and OS version 15.0

To Reproduce Steps to reproduce the behavior:

export type LocalAttachmentType = Record<string, unknown>;
export type LocalChannelType = Record<string, unknown>;
export type LocalCommandType = string;
export type LocalEventType = Record<string, unknown>;
export type LocalMessageType = Record<string, unknown>;
export type LocalReactionType = Record<string, unknown>;
export type LocalUserType = Record<string, unknown>;
const chatClient = StreamChat.getInstance<
  LocalAttachmentType,
  LocalChannelType,
  LocalCommandType,
  LocalEventType,
  LocalMessageType,
  LocalReactionType,
  LocalUserType
>(API_KEY);
const ChatScreen = (): JSX.Element => {
  return (
    <SafeAreaView>
      <Chat client={chatClient}>
      ...
      </Chat>
    </SafeAreaView>
  );
};

  1. See error types of _user are incompatible

Expected behavior

expected to compile without typescript errors.

*Screenshots Screen Shot 2021-12-02 at 10 58 29 AM *

gz#17229

skam22 avatar Dec 02 '21 18:12 skam22

Hey @skam22 could you please fork the repository and try to reproduce this issue in one of the example apps? https://github.com/GetStream/stream-chat-react-native/tree/develop/examples

vishalnarkhede avatar Dec 03 '21 07:12 vishalnarkhede

I am also experiencing this exact problem in my own application. @skam22 did you find a work around?

I've just setup the stream-chat-react-native TypeScriptMessaging example and see the same problem there too:

image

delantai avatar Dec 11 '21 09:12 delantai

I can reproduce this in our sample apps. It looks like we have a couple of types that need updating, I'm looking into it. We're working on simplifying the types for the SDK at the moment, but I'll make a PR to resolve this in the sample apps in the meantime.

madsroskar avatar Dec 11 '21 12:12 madsroskar

#This is a bit trickier to work around than I thought, so I don't have a solution just yet. For the time being, you could tell typescript to expect there to be an error reported there with @ts-expect-error in a comment on the line above the line it's reporting the error to suppress the error message until we have a proper solution in place.

This seems to be an issue with our js client checking the wrong type for the User when it's being updated from an Event, so it looks like we'll have to fix the type definition there.

I'm creating an issue in our internal issue tracker, thanks for reporting it!

madsroskar avatar Dec 13 '21 07:12 madsroskar

@delantai sorry for the late reply, I actually had implemented what @madsroskar suggested, basically commenting out the typescript error since it wasn’t preventing a successful build.

and for what it’s worth - it’s not just User that has this problem, it’s present in a number of other types as well.

skam22 avatar Dec 14 '21 05:12 skam22

Thanks for the replies, very helpful!

delantai avatar Dec 15 '21 01:12 delantai

Side note, I'm seeing a similar thing for the channel typing which is being passed via context in the example app.

In the onSelect of ChannelListScreen in the example app I'm seeing this:

image

In my app I'm also trying to access a channel in state via hook, and having the same difficulties as above.

delantai avatar Dec 15 '21 02:12 delantai

Hey team! Please add your planning poker estimate with ZenHub @Enigma-I-am @khushal87 @madsroskar @santhoshvai @vishalnarkhede

vanGalilea avatar May 10 '22 08:05 vanGalilea

Relates to 1357

vanGalilea avatar May 23 '22 06:05 vanGalilea

This issue has become stale due to the old SDK version. Please see our typescript messaging example to see a working solution.

vanGalilea avatar Mar 27 '23 09:03 vanGalilea