Skip to content
Logo

T.derive

A value computed from other schemas' fabricated values, without wrapping them in a throwaway object.

T.derive({
  to: T.string,
  from: [T.always("hello"), T.string.as(() => "world")],
}).as((parts) => parts.join(":"));
// "hello:world"

from is a tuple of schemas. Each one is fabricated separately, with its own stream, the same way T.tuple works. to declares the result's type: a schema, or a bare builder like T.string if you only need the kind. Adapters convert to, and a resolver that returns the wrong kind throws.

.override() on a derive field checks the value against to. coverage and combinatorial enumerate the enumerable inputs in from, such as an enum or a boolean, and run resolve on each combination.

.as(resolve) is required. resolve receives the fabricated from values as a tuple, then { random, clock }. random is this node's own stream, so any extra draws still replay.

For a field computed from other fields of the same object, use .refine(({ compute }) => ...) instead. See Computed fields. Use T.derive when the inputs aren't fields of an object.