[zod-nestjs] createZodDto with optional
Opened this issue · 1 comments
af-lsh commented
Hey, I'm trying to create a DTO with optional properties. Simple setup:
export const testSchema = z.object({
field: z.string().optional(),
another: z.string(),
});
export class TestDto extends createZodDto(testSchema) {}
However it fails with:
TS2509: Base constructor return type '{ [k in keyof addQuestionMarks<baseObjectOutputType<{ field: ZodOptional<this>; another: ZodString; }>, any>]: addQuestionMarks<baseObjectOutputType<{ field: ZodOptional<...>; another: ZodString; }>, any>[k]; }' is not an object type or intersection of object types with statically known members.
27 | });
28 |
> 29 | export class TestDto extends createZodDto(testSchema) {}
I feel like this would be very basic and common use case. So I wonder what could be wrong on my side?
I followed the instructions of https://github.com/wahyubucil/nestjs-zod-openapi/ to set things up.
Thanks :)
af-lsh commented
So I just figured out I could use field: z.optional(z.string())
and it works like expected 👍
Maybe someone could still check if the other way is working somehow?