What are you trying to achieve or the steps to reproduce?
This is kinda of a Fastify doubt disguised as a TS+npm doubt.
I have an app that decorates the fastify instance with stuff and also defines a bunch of interfaces and classes. Other "local" plugins use these decorators and types "work" within the app because I extended the FastifyInstance type in my app's index.d.ts with the decorators and their types.
Then I have external plugins (in their own repos) that have their own options and some also decorate the FastifyInstance.
Both decorators and options have their types, and they are available to whomever uses the plugins because plugins also have their own index.d.ts declaring the options types and the decorators types in FastifyInstance (like in this example from the docs).
So, the app has these plugins as a dependencies, registers them, and all the types work fine - the app can "see" the plugins types.
Now, how can I do the "inverse"?
On the plugin's side, I know the the app decorated the instance with "decoratorA", but how can I pull the type from the app's types?
Also, if some of the plugins options are of "TypeABC", that is declared/defined in the app, how can I pass that type from the app to the plugins.
Anyone has a good idea of how to achieve this?
I initially declared a .d.ts file in the app, exporting all these types (types defined in the app but also used in plugin options, the "extended" FastifyInstance, ...), and added the app as a devDependency in the plugins. This creates a circular dependency on npm: plugin depends on app > app depends on plugin > ..., and npm just downloads dependencies in an infinite loop.
I can't think of other options to achieve this. Create the app's own @types/...?
Thank you in advance.
- ts: 4.x
- node version: 14
- fastify version: 3.8.0
- os: Mac
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
This is kinda of a Fastify doubt disguised as a TS+npm doubt.
I have an app that decorates the fastify instance with stuff and also defines a bunch of interfaces and classes. Other "local" plugins use these decorators and types "work" within the app because I extended the FastifyInstance type in my app's index.d.ts with the decorators and their types.
Then I have external plugins (in their own repos) that have their own options and some also decorate the FastifyInstance.
Both decorators and options have their types, and they are available to whomever uses the plugins because plugins also have their own index.d.ts declaring the options types and the decorators types in FastifyInstance (like in this example from the docs).
So, the app has these plugins as a dependencies, registers them, and all the types work fine - the app can "see" the plugins types.
Now, how can I do the "inverse"?
On the plugin's side, I know the the app decorated the instance with "decoratorA", but how can I pull the type from the app's types?
Also, if some of the plugins options are of "TypeABC", that is declared/defined in the app, how can I pass that type from the app to the plugins.
Anyone has a good idea of how to achieve this?
I initially declared a .d.ts file in the app, exporting all these types (types defined in the app but also used in plugin options, the "extended" FastifyInstance, ...), and added the app as a devDependency in the plugins. This creates a circular dependency on npm: plugin depends on app > app depends on plugin > ..., and npm just downloads dependencies in an infinite loop.
I can't think of other options to achieve this. Create the app's own @types/...?
Thank you in advance.