zod-express-middleware
zod-express-middleware copied to clipboard
TypedRequest<T> with a single parameter
I found it redundant to have to specify every parameter of TypedRequest
everytime, so I created this file, which replaces TypedRequest<TParams, TQuery, TBody>
with:
TypedRequest<S extends {
params?: z.AnyZodObject,
query?: z.AnyZodObject,
body?: z.AnyZodObject,
}>
So now, I can do:
const mySchemaParams = z.object({});
const mySchemaQuery = z.object({});
const mySchemaBody = z.object({});
export const mySchema = {
params: mySchemaParams,
query: mySchemaQuery,
body: mySchemaBody,
};
export type MyCustomRequest = TypedRequest<typeof mySchema>