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 pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More TypeScript interview questions

View all →