-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fix(typing): use generic TMessage on GiftedChat props #2488
base: master
Are you sure you want to change the base?
Conversation
Related issue src/GiftedChat.tsx:57 export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
/* Message container ref */
messageContainerRef?: React.RefObject<FlatList<IMessage>>
... i think should be: export interface GiftedChatProps<TMessage extends IMessage = IMessage> {
/* Message container ref */
messageContainerRef?: React.RefObject<FlatList<TMessage>>
... |
@anthonyespirat it looks indeed as it would make sense. Do you have a use-case with a minimum repro maybe? |
@habovh repro import { useRef } from "react";
import { FlatList } from "react-native";
import { GiftedChat, IMessage } from "react-native-gifted-chat";
type ChatMessage = IMessage & {
user: IMessage["user"] & {
isAdmin: boolean;
};
};
type Props = {
messages: ChatMessage[];
};
export const CustomChat = (props: Props) => {
const containerRef = useRef<FlatList<ChatMessage>>(null);
return (
<GiftedChat<ChatMessage>
messages={props.messages}
messageContainerRef={containerRef} // Type 'RefObject<FlatList<ChatMessage>>' is not assignable to type 'RefObject<FlatList<IMessage>>'.
/>
);
}; |
@anthonyespirat I've updated this PR to include your suggestion, thanks! Edit: if you have an open issue that this PR would fix please mention it on this PR as well so it can get automatically closed |
Hi, this changes look great, why is this hasn't merged? |
@benny-cloudfm very good question indeed. Also it's been open for so long now there are conflicts so I guess someone would have to dive in and address those. |
I made a new PR including changes from this PR: |
When using a custom type for message object, GiftedChat component needs to properly use type parameters when defining props.
Following deb4c45, the type parameter from the generic
TMessage
when declaring the class component props got lost in translation and thus broke previously valid use cases with custom message object types.Despite some efforts in 39720e3, the type parameter still wasn't used and it did not fix this use-case.
This PR adds back the generic type parameter to GiftedChat's props.
Minimum repro
Patch
For those who want to quickly fix the typing issue locally, you may use the following patch.
Patch for node_modules