From a331c62bb5fac7ca158c573ac6d9904c3c1bd5eb Mon Sep 17 00:00:00 2001 From: Michael H Date: Fri, 11 Jul 2025 04:49:26 +1000 Subject: [PATCH] types: Bun.serve routes supportes Bun.file's (#20919) --- packages/bun-types/bun.d.ts | 8 ++++++- test/integration/bun-types/fixture/html.html | 0 .../bun-types/fixture/serve-types.test.ts | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 test/integration/bun-types/fixture/html.html diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index eec0782497..0e7d0bb080 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -3510,7 +3510,13 @@ declare module "bun" { [K in HTTPMethod]?: RouteHandlerWithWebSocketUpgrade; }; - type RouteValue = Response | false | RouteHandler | RouteHandlerObject | HTMLBundle; + type RouteValue = + | Response + | false + | RouteHandler + | RouteHandlerObject + | HTMLBundle + | BunFile; type RouteValueWithWebSocketUpgrade = | RouteValue | RouteHandlerWithWebSocketUpgrade diff --git a/test/integration/bun-types/fixture/html.html b/test/integration/bun-types/fixture/html.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integration/bun-types/fixture/serve-types.test.ts b/test/integration/bun-types/fixture/serve-types.test.ts index f1c4686beb..d8934baa50 100644 --- a/test/integration/bun-types/fixture/serve-types.test.ts +++ b/test/integration/bun-types/fixture/serve-types.test.ts @@ -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; + +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);