zod icon indicating copy to clipboard operation
zod copied to clipboard

Getting maxLength

Open smcardle opened this issue 1 year ago • 0 comments

Hi. I want to check if a property of a schema has a maxLength. If I try the following I get an error because unwrap() either does NOT exist because it's not optional OR because .maxLength does not exist on on it if it IS optional ERROR IS - Property 'maxLength' does not exist on type 'ZodOptional<ZodString>'.

            const maxLen = PatientDetails.shape.familyName.isOptional() ?  PatientDetails.shape.familyName.unwrap().maxLength || undefined : PatientDetails.shape.familyName.maxLength || undefined

I just want to reliable check if it has a maxLength or not no matter if it optional or not.

Anybody know how to do this ??? I am sing TypeScript if that make any difference i.e the above failure.

smcardle avatar Dec 10 '22 09:12 smcardle