Tradeoffs and Ergonomics
You'll learn: When the safety benefits of nominal typing justify the boilerplate and friction it introduces.
The Central Question
You've learned powerful techniques like brand types and smart constructors to prevent type misuse. But these patterns don't come free. Every time you add nominal typing, you're making a conscious trade: compile-time safety vs developer convenience.
The question isn't "can I make this nominally typed?" — it's "should I?"
Understanding the Costs
Nominal typing introduces friction:
- More verbose code — wrapping and unwrapping values
- Smart constructors required — no direct literal assignment
- Team learning curve — explaining brand symbols to new developers
- Refactoring overhead — changing brands propagates through codebases
- Type complexity — intersection types in error messages
Think of it like security checkpoints at an airport. More checkpoints catch more threats, but they also slow everyone down. The right answer depends on the value of what you're protecting.
When Branding Is Worth It
Use nominal typing when:
- The confusion cost is high — mixing up user IDs and product IDs could corrupt data
- The domain demands it — currencies, measurements, validated inputs
- The API surface is small — a few branded types, not dozens
- The validation is meaningful — the smart constructor actually checks something
- The error would be silent — structural typing would accept wrong values
When It's Overkill
Skip branding when:
- Types are only used in one small module
- The distinction is obvious from context
- You're just wrapping strings with no validation
- The team finds it more confusing than helpful
Key Takeaway: Nominal typing is a sharp tool — powerful when applied to high-value problems, but excessive ceremony when overused. Choose it deliberately for domains where mixing types would be catastrophic, and trust structural typing everywhere else.