Repository navigation
Commit 77a33fc
committed
feat(v4): expose optionsMap and get(value) on ZodDiscriminatedUnion
Adds a public, type-safe way to access discriminated union members by
their discriminator value, replacing the need to reach into
_zod.propValues or to iterate options manually.
- core: promote the internal discriminator->member map to
_zod.optionsMap (lazy), typed as ReadonlyMap<Primitive, Options[number]>.
- classic: add `optionsMap` getter and `get(value)` method on
ZodDiscriminatedUnion. `get(value)` returns the precise member schema
matching the literal value, including the case where a single member
declares multiple discriminator values via z.literal([...]).
- classic: `get` is installed once per prototype via _installLazyMethods;
`optionsMap` is set up via util.defineLazy to match the existing
pattern used for ZodObject's `shape`.
Refs colinhacks#5086.1 parent fbe8ad1 commit 77a33fc
3 files changed
Lines changed: 65 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1599 | 1599 | | |
1600 | 1600 | | |
1601 | 1601 | | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1602 | 1620 | | |
1603 | 1621 | | |
1604 | 1622 | | |
| |||
1607 | 1625 | | |
1608 | 1626 | | |
1609 | 1627 | | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
1610 | 1632 | | |
1611 | 1633 | | |
1612 | 1634 | | |
1613 | 1635 | | |
1614 | 1636 | | |
1615 | 1637 | | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
1616 | 1644 | | |
1617 | 1645 | | |
1618 | 1646 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
692 | 692 | | |
693 | 693 | | |
694 | 694 | | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2348 | 2348 | | |
2349 | 2349 | | |
2350 | 2350 | | |
| 2351 | + | |
2351 | 2352 | | |
2352 | 2353 | | |
2353 | 2354 | | |
| |||
2381 | 2382 | | |
2382 | 2383 | | |
2383 | 2384 | | |
2384 | | - | |
| 2385 | + | |
2385 | 2386 | | |
2386 | 2387 | | |
2387 | 2388 | | |
| |||
2395 | 2396 | | |
2396 | 2397 | | |
2397 | 2398 | | |
2398 | | - | |
| 2399 | + | |
2399 | 2400 | | |
2400 | 2401 | | |
2401 | 2402 | | |
| |||
2411 | 2412 | | |
2412 | 2413 | | |
2413 | 2414 | | |
2414 | | - | |
| 2415 | + | |
2415 | 2416 | | |
2416 | 2417 | | |
2417 | 2418 | | |
| |||
2430 | 2431 | | |
2431 | 2432 | | |
2432 | 2433 | | |
2433 | | - | |
| 2434 | + | |
2434 | 2435 | | |
2435 | 2436 | | |
2436 | 2437 | | |
| |||

0 commit comments