zod icon indicating copy to clipboard operation
zod copied to clipboard

Discriminated union example fails to parse

Open matthewfallshaw opened this issue 2 years ago • 1 comments

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:

matthewfallshaw avatar Dec 17 '22 05:12 matthewfallshaw

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...

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 Dec 17 '22 05:12 netlify[bot]

Good catch, thanks!

colinhacks avatar Dec 24 '22 08:12 colinhacks