-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript bug when used in conjunction with "fastify-type-provider-zod". #220
Comments
I have no clue why this is happening unfortunately. A PR to fix would be awesome. |
Great I will fork the repo and play around with the type definitions. If I come up with a fix I will add a PR. Thanks for the feedback! |
Just want to update you on this. Apparently, this issue exists with other type providers as well as you can see in this issue on the fastify-type-provider-typebox package. It seems the problem is the return type of the |
I was poking around with The passing case: jsonSchemaToTS.route({
method: 'GET',
url: '/with-param',
schema: {body: {type: 'object', properties: {param: {type: 'string'}}, required: ['param']}},
preHandler: jsonSchemaToTS.auth([]),
handler: (req) => {
expectType<{ param: string, [x: string]: unknown }>(req.body)
}
}) The failing case ( jsonSchemaToTS.get("/test", {
preHandler: jsonSchemaToTS.auth([]),
schema: { body: { type: 'object', properties: { param: { type: 'string' } }, required: ['param'] } },
}, (req) => {
expectType<{ param: string, [x: string]: unknown }>(req.body)
}) As mentioned by @geovla93, the failing case starts to work if we do Update: just found that this also works jsonSchemaToTS.get("/test", {
preHandler: jsonSchemaToTS.auth([]),
schema: { body: { type: 'object', properties: { param: { type: 'string' } }, required: ['param'] } },
handler: (req) => {
expectType<{ param: string, [x: string]: unknown }>(req.body)
}
}) |
I was experiencing a similar issue with |
Prerequisites
Fastify version
4.25.2
Plugin version
4.4.0
Node.js version
20.9.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
14.2.1
Description
I came across a weird bug today when I was building my API. Basically when using
@fastify/auth
plugin along withfastify-type-provider-zod
package typescript complains. I get the following error:The error is shown both in
onRequest
andpreHandler
hooks. I should mention that the error does not show up if I remove theapp.auth()
function and use the auth functions on their own or in an array.Steps to Reproduce
Create a fastify server and install the mentioned packages along with
zod
. Create two auth functions and try to use them in eitheronRequest
orpreHandler
hooks.Expected Behavior
I would like to use this package without this typescript error like this:
The text was updated successfully, but these errors were encountered: