← All Exercises

Branded Types for Nominal Typing

advancedtypescript~30min

Background

Branding adds a unique type-level marker to create nominal typing in TypeScript structural type system.

Problem

Create branded types for Email and UserId that are structurally strings but nominally distinct, preventing accidental mixing.

Input

Strings that should be branded as specific domain types.

Output

Branded string types that cannot be accidentally mixed.

Sample tests

Sample 1

Input: Email branded "[email protected]"
Expected: Valid Email type

Your solution

Learning objective

Learn branded types for nominal type safety in TypeScript structural type system.