Skip to content

Commit

Permalink
Discriminated union example fails to parse (#1713)
Browse files Browse the repository at this point in the history
https://zod.dev/?id=discriminated-unions

``` typescript
myUnion.parse({ type: "success", data: "yippie ki yay" });
```
→ ❌
``` json
    ZodError: [
      {
        "code": "invalid_union_discriminator",
        "options": [
          "success",
          "failed"
        ],
        "path": [
          "status"
        ],
        "message": "Invalid discriminator value. Expected 'success' | 'failed'"
      }
    ]
```

``` typescript
myUnion.parse({ status: "success", data: "yippie ki yay" });
```
→ ✅
  • Loading branch information
matthewfallshaw committed Dec 24, 2022
1 parent 991c947 commit 49770ac
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ const myUnion = z.discriminatedUnion("status", [
z.object({ status: z.literal("failed"), error: z.instanceof(Error) }),
]);

myUnion.parse({ type: "success", data: "yippie ki yay" });
myUnion.parse({ status: "success", data: "yippie ki yay" });
```

## Records
Expand Down

0 comments on commit 49770ac

Please sign in to comment.