Closed lifeiscontent closed 1 month ago
That code is not accessible. My guess is this would be fixed in https://github.com/fastify/fastify/pull/5672.
@mcollina sorry, I've added the code to the PR
though you are correct, I believe #5672 would be a way of solving it.
Let track on https://github.com/fastify/fastify/issues/5061
Prerequisites
Fastify version
4.x.x
Plugin version
No response
Node.js version
20.x
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
MacOS 14.6.1
Description
Hi, I've been looking through the docs and it seems there's something called
routeOptions
which might be what I want, but might not.I've effectively got some code that registers some data via a preHandler, and I think I'm doing things incorrectly, but basically, I'm wondering if there's some kind of typed context in fastify to disclose the attributes that will exist by the time certain preHandlers run.
Here's some controller code:
in this example, I've got some prehandlers that then are used with preValidations to check if the constraints for the route are valid, I'm using
routeOptions
to store this information, the reason why I'm not putting it directly on the request, is because I don't want to modify the request interface globally like the docs say to do because these entities only exist for a very short period of time.is there a way to type this kind of thing safely?
Link to code that reproduces the bug
No response
Expected Behavior
I'd expect to be able to pass some data through handlers in a request in a type safe way.