zod
zod copied to clipboard
Discriminated union example fails to parse
https://zod.dev/?id=discriminated-unions
…
myUnion.parse({ type: "success", data: "yippie ki yay" });
→ :x:
{
"ZodError": [{
"code": "invalid_union_discriminator",
"options": [
"success",
"failed"
],
"path": [
"status"
],
"message": "Invalid discriminator value. Expected 'success' | 'failed'"
}]
}
… because the key we want is status, not type.
Fix:
myUnion.parse({ status: "success", data: "yippie ki yay" });
→ :white_check_mark:
Deploy Preview for guileless-rolypoly-866f8a ready!
Built without sensitive environment variables
| Name | Link |
|---|---|
| Latest commit | 90450df22fb94df8a1feecf2fcaf85d372be5a51 |
| Latest deploy log | https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/639d5239685061000914409f |
| Deploy Preview | https://deploy-preview-1713--guileless-rolypoly-866f8a.netlify.app |
| Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site settings.
Good catch, thanks!