hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.63k stars 65 forks source link

Types are not accurate on fresh install #142

Closed FirstWhack closed 3 years ago

FirstWhack commented 3 years ago

4e72366bd21651872134f63a12ab04c1

This code obviously runs fine and is written according to the example in the readme. I did take note that the readme suggests asserting as NextApiResponse. I'm here to argue that should be the default implementation (or the documentation updated to show the default)

FirstWhack commented 3 years ago

I see that this API is for static typing. It does not support dynamic inference, we must assert middleware or other directly as there is no simple way for NextApiRequest to return a generic based on handlers.

This is of course the best you can expect from a project written in JS but with types defined separately. I will close the issue