Adapted from Ride Primetime’s company article. Prepared with AI drafting assistance. The code and tests below are synthetic design examples, not deployed dispatch behavior.
A rider needs to reach a building by 9 a.m. They need a ride home, but the appointment end time is unknown. If the input is just an optional return time, a blank could mean one way, return needed with no time yet, or a field the rider skipped. Those meanings should not share one value.
Capture what the rider knows
Use a tagged union. A one-way request has no return time. A discussed-later return intentionally has no time. A timed return has a time. Keep these as request facts. Availability and agreement are separate evidence from the provider.
type ReturnPlan = | { kind : "one-way" } | { kind : "return-time-unknown" } | { kind : "return-time-requested" ; at : string } ;
type Confirmation = { outbound : boolean ; return : boolean } ;
function summary ( plan : ReturnPlan , confirmed : Confirmation ) { const outbound = confirmed .…