How do you avoid a “loading and success at the same time” state?
Answer out loud or in your head first, then compare.
Answer
Instead of several independent flags, I describe the allowed variants. A result is, for example, loading, success with data, or error with a message. In TypeScript you can express this as a union with a status field. After checking the status, I know which fields I may read.
This removes some meaningless combinations and makes the UI easier to read. It doesn't guarantee the program moves between states correctly, though. When two servers update the same record, types won't replace protection in the database. For a long task it's worth explicitly adding “cancelled” and “awaiting approval” too, instead of hiding them in more flags.
Why it matters: Connects everyday TypeScript with controlling an agent's work.
Possible follow-ups: What do you do when you add a new state and it must be handled everywhere?
How did it go? Be honest — “Not yet” puts the question on your review list.
Start with
- B-P01 · What is Node.js, and how is it different from JavaScript in the browser? — JavaScript, TypeScript and Node.js
- B-P04 · What is a Promise? — JavaScript, TypeScript and Node.js
- B-P10 · What does TypeScript give you, and what doesn't it? — JavaScript, TypeScript and Node.js
Further reading
- TypeScript Handbook: Narrowing(opens in a new tab)Docs; accessed 22.10.2026. Narrowing, discriminated unions and exhaustiveness.