Skip to content
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

Cannot assign WebSocket or SockJS to IStompSocket on TypeScript #645

Open
tearfur opened this issue Feb 28, 2025 · 0 comments
Open

Cannot assign WebSocket or SockJS to IStompSocket on TypeScript #645

tearfur opened this issue Feb 28, 2025 · 0 comments

Comments

@tearfur
Copy link

tearfur commented Feb 28, 2025

Got this error:

TS2322: Type '() => WebSocket' is not assignable to type '() => IStompSocket'.
  Call signature return types 'WebSocket' and 'IStompSocket' are incompatible.
    The types of 'onmessage' are incompatible between these types.
      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.

It's really easy to reproduce with code like this:

const stompClient = new Client({ /* ... */ });

stompClient.webSocketFactory = function () {
  return new WebSocket(url);
};

This is what I have to do as a workaround:

const stompClient = new Client({ /* ... */ });

stompClient.webSocketFactory = function () {
  return new WebSocket(url) as IStompSocket;
};

stompjs 7.0.0
TypeScript 5.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant