zod icon indicating copy to clipboard operation
zod copied to clipboard

Add 'convert' effect to ZodType

Open Duncan3142 opened this issue 2 years ago • 3 comments

Add a convert method to ZodType, to allow for transforms that may fail

Closes https://github.com/colinhacks/zod/issues/1223

Hopefully the examples in the README make the use case clear

Duncan3142 avatar Jun 24 '22 16:06 Duncan3142

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 76263105950b1224e8769c64ca7dcfbfe6bb76ff
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/631794928b40320009af1203
Deploy Preview https://deploy-preview-1224--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Jun 24 '22 16:06 netlify[bot]

Definitely an interesting solution. I believe all of this can already by accomplished with ctx.addIssue inside a transform, right? Admittedly that API is a bit odd, since you still need to return a value after calling ctx.addIssue but I'm not sure it's worth introducing a new "conversion" concept. https://github.com/colinhacks/zod#validating-during-transform

colinhacks avatar Jul 18 '22 02:07 colinhacks

@colinhacks You're right, it's already possible to achieve equivalent functionality. This PR was really about introducing a cleaner API for combining refinements and transforms.

If you feel this will add an unnecessary maintenance burden, that's fair enough.

Duncan3142 avatar Jul 18 '22 09:07 Duncan3142

@colinhacks This PR appears to be stale, so I've submitted an alternative solution in a new PR https://github.com/colinhacks/zod/pull/1389

Duncan3142 avatar Sep 07 '22 18:09 Duncan3142