mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 05:42:43 +00:00
fix(types): Change Bun.serve types to allow void when using websockets (#7160)
* `Response` -> `any` * Revert previous commit & allow void in ws fetch * Added type test to check if you can upgrade connection without returning * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
4
packages/bun-types/bun.d.ts
vendored
4
packages/bun-types/bun.d.ts
vendored
@@ -2014,7 +2014,7 @@ declare module "bun" {
|
||||
this: Server,
|
||||
request: Request,
|
||||
server: Server,
|
||||
): Response | undefined | Promise<Response | undefined>;
|
||||
): Response | undefined | void | Promise<Response | undefined | void>;
|
||||
}
|
||||
|
||||
export interface UnixWebSocketServeOptions<WebSocketDataType = undefined>
|
||||
@@ -2075,7 +2075,7 @@ declare module "bun" {
|
||||
this: Server,
|
||||
request: Request,
|
||||
server: Server,
|
||||
): Response | undefined | Promise<Response | undefined>;
|
||||
): Response | undefined | void | Promise<Response | undefined | void>;
|
||||
}
|
||||
|
||||
export interface TLSWebSocketServeOptions<WebSocketDataType = undefined>
|
||||
|
||||
@@ -79,6 +79,25 @@ Bun.serve<User>({
|
||||
},
|
||||
});
|
||||
|
||||
Bun.serve({
|
||||
fetch(req, server) {
|
||||
server.upgrade(req);
|
||||
},
|
||||
|
||||
websocket: {
|
||||
open(ws) {
|
||||
console.log("WebSocket opened");
|
||||
ws.subscribe("test-channel");
|
||||
},
|
||||
|
||||
message(ws, message) {
|
||||
ws.publish("test-channel", `${message}`);
|
||||
},
|
||||
|
||||
perMessageDeflate: true,
|
||||
},
|
||||
});
|
||||
|
||||
Bun.serve({
|
||||
fetch(req) {
|
||||
throw new Error("woops!");
|
||||
|
||||
Reference in New Issue
Block a user