Custom Rules
Author your own validation decorators with registerRule, the same builder the built-ins use.
Every built-in rule is made with registerRule, and it's public API — your rules are exactly as first-class as the framework's.
A rule without options
A rule with options
The generic parameter is the options type; check receives it as the second argument:
For multiple positional arguments, take an options object (registerRule<{ min: number; max?: number }>) — that's how VerifyLength(min, max?) is built.
The definition contract
Three behaviors worth knowing:
checkcan return a string: that's a failure with a custom, per-case message. Only a literaltruecounts as a pass.operatesOn: 'array'makes the rule evaluate an array field as a whole. Value-level rules on array fields run per element, so a rule about the container (size, uniqueness, emptiness) must declare itself array-level or it will never see the array.- Your rule automatically gets the
.check()predicate for free, like every built-in.
VerifyBy (from validation/decorators/VerifyBy) is the same function under an alias, if you prefer the naming symmetry with the other decorators.