i'm working with webSocket from rxjs, and having an issue with the generic type argument.
the websocket API documentation states that request and response messages have different properties, but the generic for WebSocketSubject only accepts one type.
so we have something like:
import { webSocket } from "rxjs/webSocket";
const subject = new webSocket<MessageType>('wss://something');
subject.subscribe({
error: err => {
throw err;
},
next: msg /* this is of type MessageType, but the actual object is not the same type as what is input into `subject.next` */ => {
console.log(msg); // outputs something like: { anotherProperty: "anotherValue" }
},
complete: () => {
done();
}
});
// but this argument is also of type MessageType
subject.next({
testProperty1: "test value 1"
});
the problem is then that the type of msg in the next property of the subscribe method but also subject.next is the same, while the documentation specifies differing types (the objects have different properties) for input and output messages.
now of course it would be possible to use any or create a union type with optional parameters in order to make things work, but it would be more ideal to be able to specify one type for input messages and another for output messages. can this be achieved easily with the rxjs implementation of webSocket or do i need to write a wrapper or something in order to make this more clean?
ideally what i'd like to do would be something to the effect of the following (although of course i don't currently see that it's possible):
const subject = new webSocket<RequestMessageType, ResponseMessageType>('wss://something');