zod-express-middleware icon indicating copy to clipboard operation
zod-express-middleware copied to clipboard

TypedRequest<T> with a single parameter

Open Drarig29 opened this issue 3 years ago • 0 comments

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>

Drarig29 avatar Feb 19 '22 11:02 Drarig29