Skip to content
A

oneOf

function oneOf<TagKey, Base, Branches, P>(opts): OneOfProducer<OneOfOut<TagKey, Base, Branches>, P> & object;

Defined in: src/core/producer.ts:370

An honest discriminated union. base fields are parsed once; the first branch whose when XPath exists is parsed and merged, with its literal tag written under tagAs.

The output type is inferred: a discriminated union keyed on tagAs, each member being the shared base fields plus that branch’s fields plus the literal tag. Presence is honoured throughout (omit → optional key).

Type ParameterDefault type
TagKey extends string-
Base extends Record<string, Producer<unknown, Presence>>-
Branches extends readonly BranchInput<string, Record<string, Producer<unknown, Presence>>>[]-
P extends Presence"optional"
ParameterType
optsobject & BaseMeta

OneOfProducer<OneOfOut<TagKey, Base, Branches>, P> & object