I have these TypeScript interfaces, and i want to extend HandleSendMessage with HandleMessage, but the void makes it a problem.
The project is in React.js with TypeScript and Vite, and it's part of handling sending and receiving messages, eventually, to and from the server.
How do i do this correctly?
For the moment i have this:
export interface ChatMessage {
message: string;
sessionId: string;
type: MessageType;
}
export interface HandleSendMessage {
(
chatMessage: ChatMessage,
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>,
setInput: React.Dispatch<React.SetStateAction<string>>
): void;
}
export interface HandleReceiveMessage {
(
chatMessage: ChatMessage,
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>
): void;
}
The HandleSendMessage and HandleReceiveMessage have redundant code which i try to eliminate.
I tried to combine these into a HandleMessage and extend to that, but it's not working and i suspect the "void" is causing the problem, since i'm not entirely sure how to extend into this "void".
Here's the code i tried:
export interface ChatMessage {
message: string;
sessionId: string;
type: MessageType;
}
interface HandleMessage {
(
chatMessage: ChatMessage,
setMessages: React.Dispatch<React.SetStateAction<ChatMessage[]>>
): void;
}
export interface HandleSendMessage extends HandleMessage {
(
setInput: React.Dispatch<React.SetStateAction<string>>
): void;
}
export interface HandleReceiveMessage extends HandleMessage {}
I suspect it get's extended beneath the void instead of inside the void.
Maybe I have to define the void differently? Or maybe what i'm trying to do is simply not possible?
Tried go through docs, didn't find anything specific enough. Copilot is an idiot for this.