How do I model loading and error states without booleans

Back to list2025-10-16
You

How do I model loading and error states without booleans?

ChatGPT

A discriminated union removes impossible states:

type State =
  | { status: "idle" }
  | { status: "loading" }
  | { status: "ok"; data: User[] }
  | { status: "error"; message: string };

With three booleans you can represent loading and error simultaneously; with this you cannot, and the compiler enforces handling each case.

You

Is turning on strict worth the errors it produces?

ChatGPT

Yes, incrementally. Turn on one flag at a time, starting with strictNullChecks, which finds the largest class of real bugs. Doing all of them at once produces a number so large that the team stops looking at it.

You

Any downside worth knowing before I commit?

ChatGPT

It commits you to a format that is tedious to migrate away from later. The first weeks also look worse than doing nothing, which is when most people abandon it.