Vitest and Decorators of Plugins, not coming down
Bugs5382 opened this issue · comments
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.26.1
Plugin version
4.26.1
Node.js version
20.11
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.4
Description
Not sure where to put this, so move if needed:
I am using Vitest to do unit testing. One thing I noticed is that Typescript is having a hard time understanding plugin decorators that will be loaded:
This is the best example I can give is that the server shows that MongoDB (satisfy-MongoDB plugin is being used) can not be found. When the code is run, it's okay and doesn't error run out.
The server is being returned as:
let server: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>
Steps to Reproduce
Direct Access to Code: https://github.com/JAMS-Project/node-microservice-itil/blob/43a02cc4a23ce07a4261444f7972bb38815d5c53/__tests__/basic.test.ts#L16
Expected Behavior
No response
I am closing the issue since it is expected behavior in TypeScript
.
TypeScript
only knows something that is EXPLICITLY imported
through the runnable code.
That means when you are using @fastify/autoload
, TypeScript
do not knows all information since there is no direct import
through the code.
As a workaround, you need to specify the module you use in tsconfig.json
. Or import the module one by one.
In case anyone else comes back to this, I changed:
"include": ["./**/*"]
to
"include": ["./**/*", "../src/**/*"]
... and that fixed the issue.