I have a project using next-connect
& next-iron-session
.
next-connect
by default uses <NextApiRequest, NextApiResponse>
& I'm using <NextIronRequest, NextApiResponse>
where
export type AppSession = {
session: Session
}
export type NextIronRequest = NextApiRequest & AppSession
But I'm unable to pass <NextIronRequest, NextApiResponse>
to nc
like:
return nc<NextIronRequest, NextApiResponse>({
onError: (err, _, res) => {
error(err)
res.status(500).end(err.toString())
},
})
This should solve my issue but it gives me error:
Expected 0 type arguments, but got 2.ts(2558)
I get the overload error on my handler()
function like:
export default handler()
.get('/twitter/generate-auth-link', generateAuthLink)
.get('/twitter/get-verifier-token', getVerifierToken)
I get 2 errors on each method saying:
No overload matches this call. Overload 1 of 2, '(...handlers: RequestHandler[]): NextConnect', gave the following error. Argument of type 'string' is not assignable to parameter of type 'RequestHandler'. Overload 2 of 2, '(pattern: string | RegExp, ...handlers: RequestHandler[]): NextConnect', gave the following error. Argument of type '(req: NextIronRequest, res: NextApiResponse) => Promise' is not assignable to parameter of type 'RequestHandler'. Types of parameters 'req' and 'req' are incompatible. Type 'NextApiRequest' is not assignable to type 'NextIronRequest'. Property 'session' is missing in type 'NextApiRequest' but required in type 'AppSession'.ts(2769)
No overload matches this call. Overload 1 of 2, '(...handlers: RequestHandler[]): NextConnect', gave the following error. Argument of type 'string' is not assignable to parameter of type 'RequestHandler'. Overload 2 of 2, '(pattern: string | RegExp, ...handlers: RequestHandler[]): NextConnect', gave the following error. Argument of type '(req: NextIronRequest, res: NextApiResponse) => Promise' is not assignable to parameter of type 'RequestHandler'. Types of parameters 'req' and 'req' are incompatible. Type 'NextApiRequest' is not assignable to type 'NextIronRequest'. Type 'NextApiRequest' is not assignable to type 'AppSession'.ts(2769)
How do I solve it?
My complete reproduction is here → https://github.com/deadcoder0904/twitter-api-v2-3-legged-login-using-next-connect
Turns out, I was using an old version of
next-connect
.I had cloned the repo from
next/examples
so that must be why it was on an old version.Upgrading
next-connect
fixed this issue.