The Cost-Benefit of Strictness
You'll learn: When the complexity of making impossible states impossible outweighs its benefits, and how to judge whether strict type modeling is worth the investment.
The Tension
You've learned powerful techniques to make impossible states impossible through discriminated unions, strict type separation, and exhaustive checking. But there's a critical question: should you always make every impossible state impossible?
The answer is no. Type-driven design has a cost.
When Strictness Costs Too Much
Complexity Overhead
Creating perfectly strict types can mean:
- Multiple type definitions where one used to suffice
- Complex discriminated unions with many variants
- Helper functions to construct valid states
- Mapping logic between strict internal types and external APIs
If you're modeling a simple toggle that's rarely accessed, splitting it into a complex state machine might waste more time than it saves.
Team Velocity
Your team needs to understand and maintain these types. A junior developer might struggle with advanced discriminated unions where a simple optional property would be immediately clear.
Changing Requirements
Highly specific types can make pivots harder. If business requirements shift frequently, rigid type structures become refactoring barriers rather than safety nets.
When Strictness Pays Off
Critical Paths
Payment processing, authentication flows, and data integrity checks deserve maximum strictness. The cost of a runtime bug here is catastrophic.
Shared Boundaries
Public APIs, published libraries, and cross-team contracts benefit enormously from impossible states enforcement. You can't fix bugs in code you don't control.
Long-Lived Code
If this code will live for years and be touched by many developers, upfront type investment compounds its returns over time.
The Judgment Call
Ask yourself:
- How often will this code be modified?
- What's the blast radius of a bug here?
- Will the team maintain this complexity?
- Is the impossible state actually possible in practice?
Key Takeaway: Making impossible states impossible is a powerful tool, not a dogma. Apply strictness where bugs are costly and maintenance is long-term, but favor simplicity for volatile, low-risk, or internal-only code.