Rec — record utilities
Plain JavaScript objects used as maps — Record<string, A> — are one of the most common data structures in any TypeScript codebase. Rec is a small collection of utilities for working with them in pipelines: data-last, curried, and returning Option wherever a key might not exist.
Safe lookup
Section titled “Safe lookup”Rec.lookup retrieves a value by key and returns Option to make the absence explicit:
This composes naturally with Option operations:
Transforming values
Section titled “Transforming values”map transforms every value in a record, preserving keys:
mapWithKey receives both key and value:
Filtering
Section titled “Filtering”filter keeps entries where the predicate passes:
filterWithKey receives both key and value:
Picking and omitting keys
Section titled “Picking and omitting keys”pick returns a new record with only the specified keys:
omit returns a new record with the specified keys removed:
Both are type-safe: pick returns Pick<A, K> and omit returns Omit<A, K>, so the resulting type reflects exactly which keys are present.
Merging
Section titled “Merging”merge combines two records. Keys in the second record take precedence over the first:
Keys, values, and entries
Section titled “Keys, values, and entries”fromEntries is the inverse — builds a record from key-value pairs:
entries and fromEntries pair well when you want to transform both keys and values by converting to entries, mapping, and converting back:
Inspecting size
Section titled “Inspecting size”Combining with pipe
Section titled “Combining with pipe”Because all Rec functions are curried and data-last, they chain naturally:
Each step produces a new record — no mutation, no intermediate variables.