A data record its variants refine
A data record that variants refine — data records each answering to values of its choosing fields, the fields whose values choose which variant a data record is — is written as the union of its members: in JSON Schema a definition holding oneOf the members, in TypeScript a union type, in Python <name> = Union[...]. Its members are each variant, referred to by the name of its type, and, where some combination of the choosing fields' values has no variant, a member for those combinations, named by the data record's name followed by Other: a type and a definition of their own, the type tagged with the data record's sid.
A variant holds each choosing field, required and fixed to the value it answers to, and its own fields inside the data record's field of type variant, beside the fields that field holds, or, where the data record has no such field, beside the data record's fields; the variant's node decides whether a property nobody declared is refused there and around it.
The member for the other combinations holds the data record's fields, its choosing fields required where their node says so. Its definition refuses every combination of values a variant answers to; its type gives a choosing field the values no variant answers to where one field chooses, and all its values where several do; the data record's node decides whether a property nobody declared is refused.
A field of type variant is required where its object holds a field and is not declared otherwise, whether or not variants refine its data record.
A union whose members the choosing fields tell apart is how JSON Schema, TypeScript and Python each state that a data record's fields depend on its values, and with the choosing fields required in every variant at most one member matches. A value that brings no fields of its own has no variant, as the rule on variants says (§s-z3dnru6qqdf9m6j), so the data record itself answers for it, under a name its own name gives and with its own tag.
Each member follows its own node on undeclared properties, so that no node's setting overrides another's. A runtime check can refuse every combination of values a variant claims; a type can name only the values each field holds, which is exact where one field chooses.
An object with no field in it holds nothing, so the field for it is not declared.
The links it makes
The links made to it
The tests bound to it
- skills/tools/test/unit/types.test.ts · s-nk8td3ez58gahc4 follows each node on a property nobody declared, and leaves out a field of type variant whose object would hold nothing
- skills/tools/test/unit/types.test.ts · s-nk8td3ez58gahc4 gives the other member every value of each choosing field where several choose, and refuses only the combinations a variant answers to
- skills/tools/test/unit/types.test.ts · s-nk8td3ez58gahc4 lets exactly one member hold each payment, in every language
- skills/tools/test/unit/types.test.ts · s-nk8td3ez58gahc4 sets a variant's own fields beside the data record's where it has no field of type variant, and leaves out the member nobody needs
- skills/tools/test/unit/types.test.ts · s-nk8td3ez58gahc4 writes a data record its variants refine as the union of each variant and a member for the values no variant answers to