You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.26.1
Plugin version
No response
Node.js version
18.17.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.3.1
Description
Hello! In my project I have conditionals for the FastifyRequest type based on the route config in FastifyContextConfig. For example, I can add a needsUserCountry config to FastifyContextConfig like this:
Prerequisites
Fastify version
4.26.1
Plugin version
No response
Node.js version
18.17.1
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.3.1
Description
Hello! In my project I have conditionals for the
FastifyRequest
type based on the route config inFastifyContextConfig
. For example, I can add aneedsUserCountry
config toFastifyContextConfig
like this:And then create a route like this:
The config will be handled by a hook, so the value will be set and the type is correct.
If I set needsUserCountry to false or I don't set it, it will throw an error due to
req.country
beingnever
:And if I set it to true, it will work.
In newer releases this behavior is broken.
In 4.19.0 and 4.19.1 the config type requires
url
andmethod
, passing random values makes it work. The behavior ofneedsUserCountry
works as expected.Since 4.20
url
andmethod
are no longer required, but now configs are not being detected, as if I didn't pass aconfig
object.Steps to Reproduce
Try this code with Fastify 4.18 and 4.26.1. In 4.18 it will work, in 4.26.1 types will fail.
Expected Behavior
I expect the
req
object passed to the handler to have the correct types based on the config object of the endpoint.The text was updated successfully, but these errors were encountered: