types: Bun.serve routes supportes Bun.file's (#20919)

This commit is contained in:
Michael H
2025-07-11 04:49:26 +10:00
committed by Meghan Denny
parent 06fa73a20e
commit a331c62bb5
3 changed files with 28 additions and 1 deletions

View File

@@ -3510,7 +3510,13 @@ declare module "bun" {
[K in HTTPMethod]?: RouteHandlerWithWebSocketUpgrade<T>;
};
type RouteValue<T extends string> = Response | false | RouteHandler<T> | RouteHandlerObject<T> | HTMLBundle;
type RouteValue<T extends string> =
| Response
| false
| RouteHandler<T>
| RouteHandlerObject<T>
| HTMLBundle
| BunFile;
type RouteValueWithWebSocketUpgrade<T extends string> =
| RouteValue<T>
| RouteHandlerWithWebSocketUpgrade<T>

View File

@@ -5,6 +5,7 @@ import { expect, test as it } from "bun:test";
import fs from "node:fs";
import os from "node:os";
import { join } from "node:path";
import html from "./html.html";
import { expectType } from "./utilities";
// XXX: importing this from "harness" caused a failure in bun-types.test.ts
@@ -457,6 +458,26 @@ test({
},
});
const files = {} as Record<string, Bun.BunFile>;
test({
routes: {
"/this/:test": Bun.file(import.meta.file),
"/index.test-d.ts": Bun.file("index.test-d.ts"),
// @ts-expect-error this is invalid
"/index.test-d.ts.2": () => Bun.file("index.test-d.ts"),
"/ping": new Response("pong"),
"/": html,
// @ts-expect-error this is invalid, but hopefully not for too long
"/index.html": new Response(html),
...files,
},
fetch: (req, server) => {
return new Response("cool");
},
});
test({
fetch(req, server) {
server.upgrade(req);