config question #4649
-
Hi guys, I am trying to figure out how to properly use the requestConfig, I am trying to add liveQueryStore to the fastifyContext using the code app.register(callbackRoutes, { prefix: 'callbacks', config: { liveQueryStore: liveQueryStore } }) the problem is when I am trying to access it VSCode is giving me the deprecation warning req.context.config.liveQueryStore req.routeConfig.liveQueryStore [https://github.com/fastify/fastify/blob/main/docs/Reference/Routes.md#config] One would assume that the documentation is not updated but the github issue [https://github.com//pull/4470] indicates that the documentation SHOULD have been updated at the same time as the deprecation warning being added. I just want to know what the right way is now to access my config variable and how do I tell typescript the structure of my config object? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey! Thanks for the heads up! Quickly answering your question, yes, you should be using To reflect your requirements in TS, you need to use the Regarding the documentation issue, yeah it is a leftover that we didn't notice. Would you like to submit a PR to adjust the documentation? 🙂 |
Beta Was this translation helpful? Give feedback.
Hey! Thanks for the heads up!
Quickly answering your question, yes, you should be using
req.routeConfig
instead ofroute.config
, as it will be removed in a future major version.To reflect your requirements in TS, you need to use the
interface augmentation
capabilities that Fastify provides. See the following example: https://github.com/metcoder95/fastify-split-validator/blob/a3ad0a8e32658f559bf9c36509b731bcd6140ef8/index.d.ts#LL10C27-L10C27Regarding the documentation issue, yeah it is a leftover that we didn't notice. Would you like to submit a PR to adjust the documentation? 🙂