next-joi
next-joi copied to clipboard
Typed request
Thanks for this small little, but handy middleware. Great work :clap:
I extended the default request interface to have a strongly typed parameter and thought, maybe this is also useful for others, or maybe it could even be integrated.
import type { NextApiRequest, NextApiResponse } from 'next'
export interface ValidatedApiRequest<Body = any, Query extends NextApiRequest['query'] = NextApiRequest['query']> extends NextApiRequest {
body: Body
query: Query
}
const query = Joi.object({
id: Joi.string().required(),
});
async function handler(
req: ValidatedApiRequest<undefined, {id: string}>,
res: NextApiResponse
) {
//...
}
export default validator({query}, handler;
Hi, @sualko! Thanks for taking the time to open this issue and explain your findings :-) I'd be open to exploring this since it may help us with #9.
That sounds great. I will write some lines to the other issue, because I want the same as the author :smile: