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.62k stars 65 forks source link

TypeScript - NextConnect not compatible with NextApiHandler #182

Closed osdiab closed 2 years ago

osdiab commented 2 years ago

I'm using next-connect with @sentry/nextjs, and the withApiAuthRequired() helper in that package takes an argument of NextApiHandler as defined in NextJS itself. However, when using next-connect, the NextConnect type isn't compatible with NextApiHandler, probably because Req and Res can be any type - so I'm forced to cast it to make TypeScript not complain. Would be nice if the types lined up so that wouldn't need a cast. Would be nice if I didn't need to.

hoangvvo commented 2 years ago

Did you set the generics as shown in the README section at https://github.com/hoangvvo/next-connect#typescript?

osdiab commented 2 years ago

oh i didn't realize it, thanks for pointing that out! I'll close this.