RouteHandler and TypedRouteHandler declare Response | Promise<Response>. The resolver has never required that:
Resolves route handlers from various formats:
- Functions returning Response
- Functions returning strings/objects (auto-wrapped)
wrapResponse() turns a string, number, boolean, ArrayBuffer, Uint8Array, ReadableStream, object or array into a Response, and createHandlerInvoker calls it on every plain return. So the documented idiom does not compile, and every example that returns an object has to be cast.
Widening the declared return type surfaced two places that had quietly assumed the narrow one and would hand Bun a bare object at runtime:
fluent-routing.ts— the middleware chain's terminal step returnsawait route.handler(request)directly.validation-integration.ts— the JSON-API route builder returnsawait handler(req)directly.
Both now wrap, like every other dispatch path. A route registered through the fluent API that returns { hello: 'world' } answered with a 500 before this; it answers with JSON now.
Widening is backwards compatible: a Response is still a valid return.