starts a companion, with the default seal and the options O
.implSeal(f)
registers a custom seal
.implCreate(f)
registers a function that creates a payload
.implCreate.noseal(f)
the same, bypassing the seal for a payload it always accepts
.impl(f)
adds the members f returns
.implTrait(Tr, f?)
implements a trait the type declares
.implAssoc(f)
adds the members f returns, which do not take the Val first
.build()
ends the chain, and returns the companion
Write implSeal first, then implCreate. impl, implTrait and implAssoc come next, in any
order. implSeal, implCreate and impl are written once, and the other two any number of times.
The function passed to impl, implTrait and implAssoc receives seal, create and patch,
including the ones PrivateSeal and PrivateCreate remove from the companion. It receives create
only where implCreate registered one, and patch only for a Val that holds an object payload.
the payload, with the brand removed at every depth
Patch<T>
the patch accepted for a payload
Rec<V>
a Val’s reference to itself, in its own payload
CompanionBuilder<V>
a companion’s builder, with the steps it can still take
Companion<V, M>
the companion .build() returns
You never write the builder and companion types, here or for an enum or a trait. They are exported
so that your own .d.ts can reference them when you re-export a companion.
adds a seal. E.seal runs it before the tag selects a variant
.implCreate(f)
registers E.create
.implCreate.noseal(f)
the same, bypassing the seal for a payload it always accepts
.impl(f)
adds the members f returns, which take the union
.implTrait(Tr, f?)
implements a trait the enum declares
.implAssoc(f)
adds the members f returns, which do not take the union first
.[VariantName].implSeal(f)
replaces that variant’s seal
.[VariantName].implCreate(f)
replaces that variant’s create
.[VariantName].implCreate.noseal(f)
the same, bypassing the seal for a payload it always accepts
.[VariantName].impl(f)
adds the members f returns, which take that variant
.[VariantName].implTrait(Tr, f?)
implements a trait that variant declares
.[VariantName].implAssoc(f)
adds the members f returns, which do not take that variant first
.build()
ends the chain, and returns the companion
.tag comes first if the enum has a custom tag key. Each variant’s steps follow, in the same order
as Val.companion‘s. The enum’s steps come after them, in that order. The first enum step removes
the variants’ steps from the chain.
The function passed to the enum’s impl, implTrait and implAssoc receives E.seal, and
E.create where the enum’s implCreate registered one. The function passed to a variant’s impl,
implTrait and implAssoc receives that variant’s seal, create and patch.
Enum.companion accepts the companion options in its second type
argument. They apply to the enum and every variant. To configure a specific variant’s companion, add
VariantOptions:
Option
Description
VariantOptions<N, O>
adds options O for variant N: PrivateCreate and Unpatchable<K>