Skip to content

Commit

Permalink
fix(types): Change Bun.serve types to allow void when using webso…
Browse files Browse the repository at this point in the history
…ckets (oven-sh#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>
  • Loading branch information
Didas-git and autofix-ci[bot] authored Nov 17, 2023
1 parent 6e7014c commit fbff18a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
19 changes: 19 additions & 0 deletions packages/bun-types/tests/serve.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down

0 comments on commit fbff18a

Please sign in to comment.