What is 'Branded Types' (Nominal Typing) and why use it for IDs?
Updated May 4, 2026
Short answer
Branding simulates nominal typing by adding a unique 'tag' to a type, preventing identical structural types from being swapped.
Deep explanation
TS is structural; two strings are the same. This leads to bugs where a 'UserId' (string) is passed to a function expecting an 'AccountId' (string). Branding involves intersecting a type with a unique object property. While the property doesn't exist at runtime, the compiler treats them as distinct types, forcing the developer to perform a 'validated cast' and preventing accidental swaps.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro