Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
joshfee
66 days ago
|
parent
|
context
|
favorite
| on:
Zod 4
You can use a string union to discriminate when it makes sense, but that's not the only way to discriminate and in this case you'd instead use the presence of the items themselves (essentially duck-typing with strong type guarantees)
Typescript playground:
https://www.typescriptlang.org/play/?#code/C4TwDgpgBACg9gZ2F...
johnfn
66 days ago
[–]
Now you run into the issue I mentioned in GP, where you end up writing `if (blah)` everywhere, even though you know that `blah` is definitely present.
Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
Typescript playground: https://www.typescriptlang.org/play/?#code/C4TwDgpgBACg9gZ2F...