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 feature has not already been requested
🚀 Feature Proposal
The doc suggests me to write my own declaration merging snippet to set the type of my envs object.
I would find more simple to just create a function getEnvs() for the FastifyInstance that returns the object. This function will be generic so the user can simply write something like:
typeEnvs={FOO: string}constfastify=Fastify()awaitfastify.register(fastifyEnv)constenvs=fastify.getEnvs<Envs>()// envs will be of type Envsenvs.FOO// will be a stringenvs.BAR// error: Property BAR does not exist on type Envs
and the plugin will take care of performing the declaration merging stuff for them.
The Envs type can also be generated with json-schema-to-ts so that it is always synchronized with the actual definition.
Of course this is not meant to be breaking since the users can still write their own properties for FastifyInstance and access them as they do now.
In addition, it would also be useful to have it as a FastifyRequest decorator, so that I can access my envs from within a handler with ease.
Motivation
I find more simple to use a generic function to retrieve the typed envs object than writing a declaration merging for the FastifyInstance.
Example
No response
The text was updated successfully, but these errors were encountered:
Prerequisites
🚀 Feature Proposal
The doc suggests me to write my own declaration merging snippet to set the type of my envs object.
I would find more simple to just create a function
getEnvs()
for the FastifyInstance that returns the object. This function will be generic so the user can simply write something like:and the plugin will take care of performing the declaration merging stuff for them.
The
Envs
type can also be generated with json-schema-to-ts so that it is always synchronized with the actual definition.Of course this is not meant to be breaking since the users can still write their own properties for FastifyInstance and access them as they do now.
In addition, it would also be useful to have it as a FastifyRequest decorator, so that I can access my envs from within a handler with ease.
Motivation
I find more simple to use a generic function to retrieve the typed envs object than writing a declaration merging for the FastifyInstance.
Example
No response
The text was updated successfully, but these errors were encountered: