h3 icon indicating copy to clipboard operation
h3 copied to clipboard

Type mismatch occurred when using `crossws`

Open luoling8192 opened this issue 3 weeks ago • 2 comments

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,
      },
    );
  });
}

luoling8192 avatar Dec 07 '25 16:12 luoling8192

.crossws prop is internal. How did you encounter this issue in your project?

pi0 avatar Dec 08 '25 11:12 pi0

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

luoling8192 avatar Dec 08 '25 15:12 luoling8192