Open bes opened 11 months ago
Changing the return type doesn't help either:
client.webSocketFactory = (): IStompSocket => {
return new WebSocket(myBrokerUrl);
};
TS2322: Type 'WebSocket' is not assignable to type 'IStompSocket'.
Types of property 'onmessage' are incompatible.
Type '((this: WebSocket, ev: MessageEvent<any>) => any) | null' is not assignable to type '((ev: IStompSocketMessageEvent) => any) | null | undefined'.
Type '(this: WebSocket, ev: MessageEvent<any>) => any' is not assignable to type '(ev: IStompSocketMessageEvent) => any'.
Types of parameters 'ev' and 'ev' are incompatible.
Type 'IStompSocketMessageEvent' is missing the following properties from type 'MessageEvent<any>': lastEventId, origin, ports, source, and 23 more.
This works, but feels a bit icky:
client.webSocketFactory = (): IStompSocket => {
return new WebSocket(myBrokerUrl) as IStompSocket;
};
I would rather not cast with as
if I can avoid it.
Currently I guess your workaround is alright. I can look at a better fix when I upgrade this library build to use Typescript 5.
Hello,
I recently decided to upgrade to stompjs 7 from 5.4.4, and typescript doesn't like the following code:
The compiler error is the following:
It seems that my typescript configuration expects
IStompSocketMessageEvent
to contain a lot more fields thandata?: string | ArrayBuffer;
to be compatible withMessageEvent
fromlib.dom.d.ts
.How can I work around this issue?