Skip to content

NitroWebSocket does not satisfy typeof WebSocket #114

Description

@salemkode

Summary

NitroWebSocket is not assignable to APIs expecting a standard typeof WebSocket constructor because it does not expose the static constants required by the browser WebSocket constructor contract:

  • CONNECTING
  • OPEN
  • CLOSING
  • CLOSED

Reproduction

import { NitroWebSocket } from \"react-native-nitro-websockets\";
import { ConvexReactClient } from \"convex/react\";

new ConvexReactClient(url, {
  webSocketConstructor: NitroWebSocket,
});

TypeScript reports:

Type 'typeof NitroWebSocket' is missing the following properties from type '{ new (url: string | URL, protocols?: string | string[] | undefined): WebSocket; prototype: WebSocket; readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; }': CONNECTING, OPEN, CLOSING, CLOSED

Expected behavior

If NitroWebSocket is intended to be browser-compatible enough to pass to libraries accepting a custom WebSocket constructor, it should expose the same static constants as the standard browser constructor:

NitroWebSocket.CONNECTING === 0;
NitroWebSocket.OPEN === 1;
NitroWebSocket.CLOSING === 2;
NitroWebSocket.CLOSED === 3;

Alternatively, the docs could clarify that NitroWebSocket is browser-like but not a full typeof WebSocket replacement.

Additional compatibility concern

The current docs describe readyState as string values:

\"CONNECTING\" | \"OPEN\" | \"CLOSING\" | \"CLOSED\"

The browser WebSocket API uses numeric values:

0 | 1 | 2 | 3

That may cause runtime incompatibility with libraries that compare socket.readyState === WebSocket.OPEN.

Environment

  • Package: react-native-nitro-websockets
  • Use case: passing NitroWebSocket as webSocketConstructor to Convex React client

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions