Skip to main content

Basic Usage

The .brand() modifier creates branded types, which add a compile-time distinction between values that are structurally identical but semantically different.
Brands are purely a compile-time feature. At runtime, branded values are identical to their base types.

Type Inference

By default, brands only affect the output type:
This means you can parse any string, but the result is branded.

Brand Direction

You can control whether brands apply to input, output, or both:

Output Only (Default)

Input Only

Both Input and Output

Multiple Brands

You can apply multiple brands to create a hierarchy:

Numeric and Symbol Brands

Brands can be strings, numbers, or symbols:

Branded Record Keys

Use Cases

Preventing ID Mixups

Safe Numeric Types

Domain-Driven Design

Validated vs Unvalidated Data

Brand Type Helper

Zod exports the Brand type helper for type annotations:

Runtime Behavior

Brands have no runtime overhead:
The brand exists only in the type system - at runtime it’s just the base value.

Limitations

Brands are erased at runtime. They only provide compile-time type safety in TypeScript.

Combining Brands with Validation