SpinTheMic
Pro

Interview practice question

Modelling a complex workflow with discriminated union state

Frontend Engineering · TypeScript · Experienced

A checkout flow has many states, and bugs come from invalid combinations of flags like isLoading, hasError and isPaid. How would you redesign the types?

What a strong answer covers

Your AI report card counts how many of these ideas you cover.

  • Replace boolean flags with discriminated union states.
  • Each state carries only relevant data.
  • Typed transitions functions.
  • Exhaustive handling.
  • Consider state machine library (XState).
Practise this topic

Start without signing up. Sign in free to get an AI report card on your answer.

See all topics