Skip to content

Fix/issue 4685#6758

Open
BALOGUN-DAVID wants to merge 1 commit into
fastify:mainfrom
BALOGUN-DAVID:fix/issue-4685
Open

Fix/issue 4685#6758
BALOGUN-DAVID wants to merge 1 commit into
fastify:mainfrom
BALOGUN-DAVID:fix/issue-4685

Conversation

@BALOGUN-DAVID
Copy link
Copy Markdown

Fixes #4685

This PR restores the ability for developers to provide an explicit return type via a generic type argument on RouteHandlerMethod and related routing shorthand methods. In Fastify v4, the generic return type was removed in favor of strict type inference using ResolveFastifyReplyReturnType, which unfortunately broke community plugins (like fastify-funky) and custom hooks that needed to extend or override the return type signature of route handlers.

To fix this while maintaining v4's strict default type inference, this PR introduces a new ResolveReply generic type parameter. It is placed at the end of the generics list and defaults directly to ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>. This ensures total backward compatibility for users who don't supply the parameter, while providing the requested escape hatch for those who do.

Checklist

@github-actions github-actions Bot added the typescript TypeScript related label Jun 5, 2026
Comment thread lib/schema-controller.js Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typescript TypeScript related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a way to extend route handler return type

2 participants