Skip to content
TypeScript·Intermediate·Conceptual·1 min read

Can discriminated unions model API responses?

Short interview answer

Yes, but untrusted JSON still needs runtime validation before it can be treated as the union. After validation, the discriminator provides safe control flow for success, domain error, and other response variants.

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Discriminated unions

Related questions