Try it Live
Run Hardfork examples in the interactive playground
BrandedHardfork
Branded type pattern for type-safe hardfork representation.Overview
BrandedHardfork uses TypeScript’s branded type pattern to create a distinct type from strings while maintaining runtime string behavior.Type Definition
BrandedHardfork Type
- Extends
string- all string methods available - Phantom
__tagproperty - compile-time only, no runtime overhead - Readonly - immutable by type system
- Nominal typing - distinct from plain strings
Branded Type Pattern
What is Branding?
Branding adds a phantom type property to distinguish similar types at compile time:Why Use Branding?
Type Safety:Implementation
Constants
All hardfork constants are branded strings:Factory Function
Ordering Array
Name Lookup
Usage Patterns
Type Guards
Type Assertions
Function Signatures
Advantages
1. Compile-Time Safety
2. Self-Documenting Code
3. Zero Runtime Cost
Best Practices
1. Use Factory Functions
2. Validate at Boundaries
3. Documentation
Related Branded Types
Similar pattern used throughout primitives:- Similar API patterns across primitives
- Predictable type safety
- Zero runtime overhead across all types

