Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[zod-nestjs]: required fields in zod schema are optional in dto objects #188

Open
blahetal opened this issue Feb 15, 2024 · 7 comments
Open

Comments

@blahetal
Copy link

Hi,
considering the example

export const CatZ = extendApi(
  z.object({
    name: z.string(),
    age: z.number(),
    breed: z.string(),
  }),
  {
    title: 'Cat',
    description: 'A cat',
  }
);
export class CatDto extends createZodDto(CatZ) {}
var cat: CatDto;
cat.age <<<--- data type is age?: number

all fields in the schema are required but the dto has all fields optional. Why does createZodDto do it or how can I make createZodDto to keep required fields in dto?

Thanks,
Libor

@maximeburri
Copy link

I have the same issue I don't understand this behavior.

@dmitry-zaets
Copy link

Probably you are missing "strict": true, setting in your tsconfig.json

@blahetal
Copy link
Author

Probably you are missing "strict": true, setting in your tsconfig.json

just checked it and it is set :(

@busybox11
Copy link

Looks like this could be fixed by #194

@philipjlane
Copy link

Looks like this is still broken. Everything is optional, which makes DTOs fairly pointless from a validation perspective.

@uuouter
Copy link

uuouter commented Aug 4, 2024

Anyone found a solution for this? Starting to doubt using this package now.

@alexguillon
Copy link

solved it by adding :
"strictNullChecks": true,
in my tsconfig.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants