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:
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
Summary
NitroWebSocketis not assignable to APIs expecting a standardtypeof WebSocketconstructor because it does not expose the static constants required by the browser WebSocket constructor contract:CONNECTINGOPENCLOSINGCLOSEDReproduction
TypeScript reports:
Expected behavior
If
NitroWebSocketis intended to be browser-compatible enough to pass to libraries accepting a customWebSocketconstructor, it should expose the same static constants as the standard browser constructor:Alternatively, the docs could clarify that
NitroWebSocketis browser-like but not a fulltypeof WebSocketreplacement.Additional compatibility concern
The current docs describe
readyStateas string values:The browser WebSocket API uses numeric values:
That may cause runtime incompatibility with libraries that compare
socket.readyState === WebSocket.OPEN.Environment
react-native-nitro-websocketsNitroWebSocketaswebSocketConstructorto Convex React client