colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.1k stars 1.15k forks source link

Add public API introspection of the element schema for `z.ZodSet` #3501

Open 6XGate opened 4 months ago

6XGate commented 4 months ago

Currently, z.ZodSet lacks any public API to access the schema of the set elements. I'm not sure if any is an oversight, but it would be a great addition.

Currently z.ZodArray, z.ZodRecord, and z.ZodMap all support such features. Doesn't seem to be too great an ask for a similar feature for z.ZodSet.

samchungy commented 4 months ago

You can access zodSet._def.valueType?

6XGate commented 4 months ago

The underscore would indicate that _def is not intended for public consumption and could change in the future. It would be preferred to have something that does not fall under that semantic situation.