T.choice
A literal: picks a random schema from a set, then fabricates it.
T.choice.uniform([T.always(null), T.number.whereby({ min: 0, max: 100 })]);
T.choice.weighted([
[3, T.string.whereby({ length: { max: 10 } })],
[1, T.number],
]);It works like T.enum, but picks between schemas instead of fixed values. T.enum returns one of its values as-is. T.choice picks one of its schemas and fabricates it, so each option can be random, nested, or built from other primitives.
There's no bare T.choice(...). Use .uniform or .weighted. Each weight is divided by the total of all weights. A weight of 0 turns that option off, and it throws if every weight is 0. Negative weights, NaN, and Infinity are invalid.
The options don't have to be written inline. An array built at runtime, such as limits.map((max) => T.number.whereby({ min: 0, max })), works too. Its type keeps the union of the options but not how many there are. Since it can't be checked for emptiness at compile time, an empty array throws when the schema is built.
