Skip to content

Type mismatch occurred when using crossws #1258

@luoling8192

Description

@luoling8192

Environment

h3: 2.0.1-rc.5

Reproduction

https://h3.dev/guide/advanced/websocket

Describe the bug

Here is the app.fetch's type

fetch(_request: ServerRequest): Response | Promise<Response>;

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions