CHALLENGE 3: Union Type for Status =================================== SOLUTION: type Status = "pending" | "approved" | "rejected"; function handleStatus(status: Status): void { if (status === "pending") { console.log("The request is waiting for review..."); } else if (status === "approved") { console.log("The request has been approved!"); } else if (status === "rejected") { console.log("The request was rejected."); } } // Using the function: handleStatus("approved"); // ✅ Works handleStatus("pending"); // ✅ Works handleStatus("rejected"); // ✅ Works handleStatus("ignored"); // ❌ Error! "ignored" is not a valid Status EXPLANATION: - "type Status = ..." — defines a union type - "pending" | "approved" | "rejected" — only these exact strings are valid - handleStatus(status: Status) — function only accepts a Status value - TypeScript catches typos: handleStatus("aproved") would error immediately WHY UNION TYPES MATTER: - Type safety for a fixed set of options - IDE autocomplete shows only valid options - Prevents bugs from typos: "aproved" instead of "approved" - Self-documenting: the type itself explains valid options ALTERNATIVE SOLUTION (with switch): function handleStatus(status: Status): void { switch (status) { case "pending": console.log("Waiting for review..."); break; case "approved": console.log("Approved!"); break; case "rejected": console.log("Rejected."); break; } } OR WITH OBJECT MAPPING: const statusMessages: Record = { pending: "The request is waiting for review...", approved: "The request has been approved!", rejected: "The request was rejected." }; function handleStatus(status: Status): void { console.log(statusMessages[status]); } TESTING: handleStatus("pending") // ✅ Logs message handleStatus("approved") // ✅ Logs message handleStatus("rejected") // ✅ Logs message handleStatus("unknown") // ❌ Error! Not a valid Status handleStatus("Approved") // ❌ Error! Capital A—must match exactly KEY INSIGHT: Union types with string literals create an enum-like type without the overhead. Very common pattern in real TypeScript codebases.