h3
h3 copied to clipboard
Type mismatch occurred when using `crossws`
Environment
h3: 2.0.1-rc.5
Reproduction
https://h3.dev/guide/advanced/websocket
Describe the bug
Here is the app.fetch's type
https://github.com/h3js/h3/blob/d6475e131b3a80f44bebd5b95ce3e106ed1ac258/src/types/h3.ts#L106
fetch(_request: ServerRequest): Response | Promise<Response>;
But when we use defineWebsocketHandler, the function returns crossws as an extra result
https://github.com/h3js/h3/blob/d6475e131b3a80f44bebd5b95ce3e106ed1ac258/src/utils/ws.ts#L23C1-L41C2
/**
* Define WebSocket event handler.
*
* @see https://h3.dev/guide/websocket
*/
export function defineWebSocketHandler(
hooks: Partial<WebSocketHooks>,
): EventHandler {
return defineHandler(function _webSocketHandler() {
return Object.assign(
new Response("WebSocket upgrade is required.", {
status: 426,
}),
{
crossws: hooks,
},
);
});
}
.crossws prop is internal. How did you encounter this issue in your project?
crossws prop is internal. How did you encounter this issue in your project?
https://h3.dev/guide/advanced/websocket
The official document show this way to interact with websocket