Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Valof

The Valof Book

v0.8.0

Write robust domain logic in TypeScript
just by following the conventions.

npm

The Valof Book is both a guide and a reference. Read it in order to learn the conventions, or use the sidebar to find a specific topic.

Important

Valof is pre-1.0. A minor release can change the API.

Why Valof?

Valof is an opinionated value-object helper for TypeScript that enforces the conventions through types and linting.

  • Nominal-ish typing with a phantom brand: TypeScript distinguishes one Val type from another, with nothing to pay at runtime.

  • Values as plain data: Vals stay objects, arrays and primitives. They serialize without adapters and fit directly into React and other framework state. No classes, no prototypes.

  • Immutability: Vals are immutable. Their types are deeply readonly, and their constructors copy their inputs, so an original reference cannot mutate them.

  • No as casts in your code: Valof owns the cast required to construct a branded value.

  • Companion object: Keep a type’s constructor and functions together without a class. The first Val parameter is inferred.

  • “Parse, don’t validate”: Every creation and derivation goes through one seal. Use any validation library and any Result type.

  • Copy only what changes: patch copies only the paths it changes. Untouched branches keep their reference identity.

  • Rust-like abstractions (experimental): Enum is a closed set of variants with exhaustive match. Trait shares behavior across Vals. dyn adds dynamic dispatch without classes, holding different types together.

  • Built-in linter: Catch convention violations through ESLint, Oxlint or the standalone command.

  • Lightweight: Starts from 852 B gzipped, with no runtime dependencies.

For background on individual features, see TypeScript problems Valof addresses.