Skip to main content
Voltaire uses branded types to prevent common bugs like passing a Hash where an Address is expected. The brand exists only at compile time - at runtime, it’s just a Uint8Array.

What is a Branded Type?

A branded type adds a compile-time tag to a base type:
At runtime, both are plain Uint8Array. TypeScript prevents you from mixing them up:

Zero Runtime Overhead

The brand is a phantom type - it exists only in TypeScript’s type system:

Validation at Construction

Branded types are validated when created. If you have an AddressType, it’s valid:

Console Formatting

Branded types display nicely when logged:

Using Branded Types in Function Signatures

Use branded types in your function parameters:

API Documentation Note

All Voltaire documentation shows the recommended API using constructors like Address(), Hash(), etc. These return instances with prototype methods. For bundle-size optimization, Voltaire also provides a tree-shakeable functional API with the same method signatures but imported as standalone functions.

All Branded Types

Schema Annotations

When using Effect Schema, annotate schemas with metadata for better error messages, JSON Schema generation, and form integration:
Benefits:
  • Better errors: Custom message replaces raw parse errors
  • JSON Schema: JSONSchema.make() generates OpenAPI-compatible specs
  • Form labels: title and description for UI integration
  • IDE support: Annotations surface in hover information
See Schema Annotations for complete documentation.

Learn More

Schema Annotations

Annotate schemas for better DX

Tree-Shakeable API

Functional API for minimal bundle size

Address Primitive

Complete Address API reference