ecyrbe/zodios

`app.use((err, req, res, next) => {})` get implicit any for TypeScript 5.2.2

Closed this issue · 3 comments

Version: @zodios/express 10.6.1, zod 3.22.4, @types/express 4.17.21

export const app = zodiosApp(apis);

//              ⬇️ Parameter 'err' implicitly has an 'any' type.ts(7006)
app.use((err, _req, res, next) => {
    next(err);
});

This seems to be a problem in function overloading:

interface ZodiosUse<Context extends ZodObject<any>> {
    use(...handlers: Array<ZodiosRouterContextRequestHandler<Context>>): this;
    use(handlers: Array<ZodiosRouterContextRequestHandler<Context>>): this;
    use(errorHandler: ZodiosRouterContextErrorHandler<Context>): this;
    use(path: string, ...handlers: Array<ZodiosRouterContextRequestHandler<Context>>): this;
    use(path: string, handlers: Array<ZodiosRouterContextRequestHandler<Context>>): this;
}

If I just remove all but use(errorHandler: ZodiosRouterContextErrorHandler<Context>): this;, the implicit any error is gone. Or if I just remove use(...handlers: Array<ZodiosRouterContextRequestHandler<Context>>): this;

You might be on to something here with function overloading being the issue and this could even be related to #505 (comment)

In every project I'm using Zodios in, I'm eventually seeing more and more "implicit any" warnings which go away when restarting the TS language server in VS Code or sometimes even just saving my current file. Looks like TS gets confused as to what typings to pick or something like that (just like you suggested).

Unfortunately, it seems @ecyrbe is on an extended hiatus at the moment. I sincerely hope, he's gonna come back to work on Zodios because it is such an awesome library. 🙏

You might be on to something here with function overloading being the issue and this could even be related to #505 (comment)

In every project I'm using Zodios in, I'm eventually seeing more and more "implicit any" warnings which go away when restarting the TS language server in VS Code or sometimes even just saving my current file. Looks like TS gets confused as to what typings to pick or something like that (just like you suggested).

Unfortunately, it seems @ecyrbe is on an extended hiatus at the moment. I sincerely hope, he's gonna come back to work on Zodios because it is such an awesome library. 🙏

This issue doesn't resolve even if you restart the ts server. And it happens without complex settings.(even when the api is empty array)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.