What is a discriminated union in TypeScript?
spaceto flip
A union type where each variant has a common literal property (the discriminant) that lets TypeScript narrow the type. Example: type State = { kind: 'loading' } | { kind: 'success'; data: string } | { kind: 'error'; message: string }. Switching on 'kind' gives type-safe access to variant-specific fields.