One Simple Trick to Better Types
When building APIs, it's easy to create types that look fine at first glance but can actually allow impossible or contradictory states. Thinking of types as sets of values provides a simple way to reason about all possible states a type can hold, known as its cardinality. By reducing unnecessary states and using discriminated unions instead of multiple boolean flags, you can create types that are precise, safe, and clear-preventing bugs and making your code easier to understand and maintain.
mechanicalrock.io